private async void SendCommand(PlaceTask task) { var endpointConfiguration = new EndpointConfiguration("TaskHandler"); var transport = endpointConfiguration.UseTransport <MsmqTransport>(); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.EnableInstallers(); var routing = transport.Routing(); routing.RouteToEndpoint(typeof(PlaceTask), "TaskHandler"); endpointConfiguration.UseSerialization <JsonSerializer>(); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); await endpointInstance.Send(task) .ConfigureAwait(false); await endpointInstance.Stop() .ConfigureAwait(false); }
public async Task SagaTest() { //Arrange SagaTask saga = new SagaTask(_mockTaskManager) { Data = new PlaceSagaTask() }; var context = new TestableMessageHandlerContext(); var placeTask = new PlaceTask() { TaskId = 1 }; var zipTask = new ArchiveTask() { TaskId = placeTask.TaskId, ZipPath = "" }; _mockTaskManager.Stub(t => t.DownloadSite(placeTask.TaskId)).Return(zipTask); //Act await saga.Handle(placeTask, context) .ConfigureAwait(false); var stage1 = (ArchiveTask)context.SentMessages[0].Message; await saga.Handle(zipTask, context) .ConfigureAwait(false); var stage2 = (ArchiveTask)context.SentMessages[0].Message; //Assert _mockTaskManager.AssertWasCalled(t => t.DownloadSite(stage1.TaskId)); _mockTaskManager.AssertWasCalled(t => t.ArchiveSite(stage1)); Assert.AreEqual(placeTask.TaskId, stage2.TaskId); }
public Task Handle(PlaceTask message, IMessageHandlerContext context) { log.Info($"newTask, TaskId = {message.TaskId}"); //ArchiveTask zipTask = new ArchiveTask(); var zipTask = _taskManager.DownloadSite(message.TaskId); return(context.SendLocal(zipTask)); }
public PlaceTask Create(string url) { PlaceTask cTask = new PlaceTask { TaskId = _taskRepository.AddTask(url, "pending") }; _nsBusProvider.SendTaskCreatedMessage(cTask); return(cTask); }
public void Run() { IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Any, 0); while (true) { Byte[] receiveBytes = client.Receive(ref iPEndPoint); string message = Encoding.ASCII.GetString(receiveBytes); PlaceTask task = JsonSerializer.Deserialize <PlaceTask>(message); Console.WriteLine("received task: " + task.taskName); //Console.WriteLine("received task: " + task.place.addedBy.username); ProcessTask(task); } }
public PlaceTask CreateTask(string url) { PlaceTask cTask = new PlaceTask(); try { cTask.TaskId = _taskRepository.AddTask(url); } catch { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest; } SendCommand(cTask); WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created; return(cTask); }
private void ProcessTask(PlaceTask task) { switch (task.taskName) { case "addPlace": OnNewPlace?.Invoke(task.place); break; case "updatePlace": OnUpdatePlace?.Invoke(task.place); break; case "deletePlace": OnDeletePlace?.Invoke(task.place); break; default: Console.WriteLine("¯\\_(ツ)_/¯"); break; } }
public void SendTaskCreatedMessage(PlaceTask task) { SendCommand(task); }