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(); }
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); }
public void StartConsumer_Valid_BasicConsumeCalled() { // Arrange string subject = "test"; Mock <IModel> modelMock = new Mock <IModel>(); Mock <EventingBasicConsumer> consumerMock = new Mock <EventingBasicConsumer>(modelMock.Object); modelMock.Setup(x => x.BasicConsume(subject, false, "", false, false, null, consumerMock.Object)).Verifiable(); RabbitMQListener listener = new RabbitMQListener(modelMock.Object); // Act listener.StartConsumer(consumerMock.Object, subject); // Assert modelMock.Verify(); }
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(); }