private static void Main() { string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); // Appsettings is renamed because of an issue where the project loaded another appsettings.json IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettingsnotificationsystem.json", true, true) .AddJsonFile($"appsettingsnotificationsystem.{environmentName}.json", true, true) .AddEnvironmentVariables() .Build(); Config config = configuration.GetSection("App").Get <Config>(); IRabbitMQConnectionFactory connectionFactory = new RabbitMQConnectionFactory(config.RabbitMQ.Hostname, config.RabbitMQ.Username, config.RabbitMQ.Password); RabbitMQSubscriber subscriber = new RabbitMQSubscriber(connectionFactory); IModel channel = subscriber.SubscribeToSubject("EMAIL"); RabbitMQListener listener = new RabbitMQListener(channel); // inject your notification service here ISendGridClient sendGridClient = new SendGridClient(config.SendGrid.ApiKey); INotificationService notificationService = new EmailSender(sendGridClient, config.SendGrid.EmailFrom, config.SendGrid.SandboxMode); EventingBasicConsumer consumer = listener.CreateConsumer(notificationService); listener.StartConsumer(consumer, "EMAIL"); Console.ReadLine(); }
public void SetCallBack_Valid_EventHandlerAdded() { // Arrange string payload = "test"; byte[] payloadBytes = Encoding.UTF8.GetBytes(payload); ReadOnlyMemory <byte> readOnlyMemory = new ReadOnlyMemory <byte>(payloadBytes); BasicDeliverEventArgs eventArgs = new BasicDeliverEventArgs(null, 1, false, null, null, null, readOnlyMemory); Mock <IModel> modelMock = new Mock <IModel>(); modelMock.Setup(x => x.BasicAck(eventArgs.DeliveryTag, false)) .Verifiable(); Mock <EventingBasicConsumer> consumerMock = new Mock <EventingBasicConsumer>(modelMock.Object); Mock <ICallbackService> notificationmock = new Mock <ICallbackService>(); notificationmock.Setup(x => x.ParsePayload(It.Is <string>(x => x == payload))).Verifiable(); notificationmock.Setup(x => x.ValidatePayload()).Verifiable(); notificationmock.Setup(x => x.ExecuteTask()).Verifiable(); RabbitMQListener listener = new RabbitMQListener(modelMock.Object); // Act listener.CreateConsumer(notificationmock.Object); listener.SetCallBack(notificationmock.Object, consumerMock.Object); listener.CallBack(notificationmock.Object, eventArgs); // Assert notificationmock.Verify(); }
protected override Task ExecuteAsync(CancellationToken stoppingToken) { RabbitMQSubscriber subscriber = new RabbitMQSubscriber( new RabbitMQConnectionFactory(config.RabbitMQ.Hostname, config.RabbitMQ.Username, config.RabbitMQ.Password)); IModel channel = subscriber.SubscribeToSubject(subject); RabbitMQListener listener = new RabbitMQListener(channel); ICallbackService documentDeleterService = new DocumentDeleter(config, restClient); EventingBasicConsumer consumer = listener.CreateConsumer(documentDeleterService); listener.StartConsumer(consumer, subject); return(Task.CompletedTask); }
private static void Main() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System", LogEventLevel.Warning) .Enrich.FromLogContext() .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate) .CreateLogger(); string environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); // Appsettings is renamed because of an issue where the project loaded another appsettings.json IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettingsnotificationsystem.json", true, true) .AddJsonFile($"appsettingsnotificationsystem.{environmentName}.json", true, true) .AddEnvironmentVariables() .Build(); Config config = configuration.GetSection("App") .Get <Config>(); IRabbitMQConnectionFactory connectionFactory = new RabbitMQConnectionFactory(config.RabbitMQ.Hostname, config.RabbitMQ.Username, config.RabbitMQ.Password); RabbitMQSubscriber subscriber = new RabbitMQSubscriber(connectionFactory); IModel channel = subscriber.SubscribeToSubject("EMAIL"); RabbitMQListener listener = new RabbitMQListener(channel); // inject your notification service here ISendGridClient sendGridClient = new SendGridClient(config.SendGrid.ApiKey); ICallbackService notificationService = new EmailSender(sendGridClient, config.SendGrid.EmailFrom, config.SendGrid.SandboxMode); EventingBasicConsumer consumer = listener.CreateConsumer(notificationService); listener.StartConsumer(consumer, "EMAIL"); Console.ReadLine(); }