public async Task WebHookWorkItemSendTests() { var services = new ServiceCollection(); services.AddHarpoon(c => c.SendWebHookWorkItemsUsingMassTransit()); services.AddMassTransit(p => Bus.Factory.CreateUsingRabbitMq(cfg => { var host = cfg.Host(new Uri("rabbitmq://localhost:5672"), hostConfigurator => { hostConfigurator.Username("guest"); hostConfigurator.Password("guest"); }); cfg.ConfigureWebHookWorkItemsConsumer(p, "WebHookWorkItemsQueue"); }), x => x.ReceiveWebHookWorkItemsUsingMassTransit()); var processor = new QueuedProcessor <IWebHookWorkItem>(); services.AddSingleton(typeof(IQueuedProcessor <IWebHookWorkItem>), processor); var provider = services.BuildServiceProvider(); var token = new CancellationTokenSource(); await provider.GetRequiredService <IHostedService>().StartAsync(token.Token); var service = provider.GetRequiredService <IWebHookSender>(); await service.SendAsync(new WebHookWorkItem(Guid.NewGuid(), new WebHookNotification(), new WebHook()), CancellationToken.None); await Task.Delay(10000); Assert.Equal(1, processor.Counter); token.Cancel(); }
public async Task NotificationSendTests() { var services = new ServiceCollection(); services.AddHarpoon(c => c.SendNotificationsUsingMassTransit()); services.AddMassTransit((IServiceCollectionConfigurator p) => { p.ReceiveNotificationsUsingMassTransit(); p.AddBus(p => Bus.Factory.CreateUsingRabbitMq(cfg => { var host = cfg.Host(new Uri("rabbitmq://localhost:5672"), hostConfigurator => { hostConfigurator.Username("guest"); hostConfigurator.Password("guest"); }); cfg.ConfigureNotificationsConsumer(p, "NotificationsQueue"); })); }); services.AddMassTransitHostedService(); var processor = new QueuedProcessor <IWebHookNotification>(); services.AddSingleton(typeof(IQueuedProcessor <IWebHookNotification>), processor); var provider = services.BuildServiceProvider(); try { await provider.GetRequiredService <IHostedService>().StartAsync(default);
public async Task NotificationSendTests() { var services = new ServiceCollection(); services.AddHarpoon(c => c.SendNotificationsUsingMassTransit()); services.AddMassTransit(p => Bus.Factory.CreateUsingRabbitMq(cfg => { var host = cfg.Host(new Uri("rabbitmq://localhost:5672"), hostConfigurator => { hostConfigurator.Username("guest"); hostConfigurator.Password("guest"); }); cfg.ConfigureNotificationsConsumer(p, "NotificationsQueue"); }), x => x.ReceiveNotificationsUsingMassTransit()); var processor = new QueuedProcessor <IWebHookNotification>(); services.AddSingleton(typeof(IQueuedProcessor <IWebHookNotification>), processor); var provider = services.BuildServiceProvider(); var token = new CancellationTokenSource(); await provider.GetRequiredService <IHostedService>().StartAsync(token.Token); var service = provider.GetRequiredService <IWebHookService>(); await service.NotifyAsync(new WebHookNotification { TriggerId = "trigger", Payload = new Dictionary <string, object> { ["key"] = "value" } }); await Task.Delay(10000); Assert.Equal(1, processor.Counter); token.Cancel(); }
protected void InitalizeBuffer(CancellationToken token = default) { _buffer = new QueuedProcessor <string>(ProcessJsonAsync, token); JsonProvider.Message += OnClientMessage; }