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 SubscribeToSubject_Valid_IModel() { // Arrange Mock <IModel> modelMock = new Mock <IModel>(); modelMock.Setup(x => x.QueueDeclare(It.IsAny <string>(), It.Is <bool>(x => x == true), It.Is <bool>(x => x == false), It.Is <bool>(x => x == false), null)).Verifiable(); modelMock.Setup(x => x.BasicQos(It.Is <uint>(x => x == 0), It.Is <ushort>(x => x == 1), It.Is <bool>(x => x == false) )).Verifiable(); Mock <IConnection> connectionMock = new Mock <IConnection>(); connectionMock.Setup(x => x.CreateModel()).Returns(modelMock.Object); Mock <IRabbitMQConnectionFactory> connectionFactoryMock = new Mock <IRabbitMQConnectionFactory>(); connectionFactoryMock.CallBase = true; connectionFactoryMock.Setup(x => x.CreateConnection()).Returns(connectionMock.Object); RabbitMQSubscriber rabbitMQSubscriber = new RabbitMQSubscriber(connectionFactoryMock.Object); // Act IModel channel = rabbitMQSubscriber.SubscribeToSubject("EMAIL"); // Assert connectionFactoryMock.Verify(); connectionMock.Verify(); modelMock.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(); }