private void RunMessageBrokerReceivers(IServiceProvider serviceProvider)
        {
            var fileUploadedMessageQueueReceiver        = serviceProvider.GetService <IMessageReceiver <FileUploadedEvent> >();
            var fileDeletedMessageQueueReceiver         = serviceProvider.GetService <IMessageReceiver <FileDeletedEvent> >();
            var emailMessageCreatedMessageQueueReceiver = serviceProvider.GetService <IMessageReceiver <EmailMessageCreatedEvent> >();
            var smsMessageCreatedMessageQueueReceiver   = serviceProvider.GetService <IMessageReceiver <SmsMessageCreatedEvent> >();

            var notification = new SignalRNotification();
            var endpoint     = $"{AppSettings.NotificationServer.Endpoint}/SimulatedLongRunningTaskHub";

            fileUploadedMessageQueueReceiver?.Receive(data =>
            {
                Thread.Sleep(5000); // simulate long running task

                string message = data.FileEntry.Id.ToString();

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"{AppSettings.MessageBroker.Provider} - File Uploaded", Message = message });
            });

            fileDeletedMessageQueueReceiver?.Receive(data =>
            {
                Thread.Sleep(5000); // simulate long running task

                string message = data.FileEntry.Id.ToString();

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"{AppSettings.MessageBroker.Provider} - File Deleted", Message = message });
            });

            emailMessageCreatedMessageQueueReceiver?.Receive(data =>
            {
                string message = data.Id.ToString();

                // TODO: code send mail here

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"Send Email", Message = message });
            });

            smsMessageCreatedMessageQueueReceiver?.Receive(data =>
            {
                string message = data.Id.ToString();

                // TODO: code send sms here

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"Send Sms", Message = message });
            });
        }
Пример #2
0
        private void RunMessageBrokerReceivers()
        {
            IMessageReceiver <FileUploadedEvent> fileUploadedMessageQueueReceiver = null;
            IMessageReceiver <FileDeletedEvent>  fileDeletedMessageQueueReceiver  = null;

            if (AppSettings.MessageBroker.UsedRabbitMQ())
            {
                fileUploadedMessageQueueReceiver = new RabbitMQReceiver <FileUploadedEvent>(new RabbitMQReceiverOptions
                {
                    HostName  = AppSettings.MessageBroker.RabbitMQ.HostName,
                    UserName  = AppSettings.MessageBroker.RabbitMQ.UserName,
                    Password  = AppSettings.MessageBroker.RabbitMQ.Password,
                    QueueName = AppSettings.MessageBroker.RabbitMQ.QueueName_FileUploaded,
                    AutomaticCreateEnabled = true,
                    ExchangeName           = AppSettings.MessageBroker.RabbitMQ.ExchangeName,
                    RoutingKey             = AppSettings.MessageBroker.RabbitMQ.RoutingKey_FileUploaded,
                });

                fileDeletedMessageQueueReceiver = new RabbitMQReceiver <FileDeletedEvent>(new RabbitMQReceiverOptions
                {
                    HostName  = AppSettings.MessageBroker.RabbitMQ.HostName,
                    UserName  = AppSettings.MessageBroker.RabbitMQ.UserName,
                    Password  = AppSettings.MessageBroker.RabbitMQ.Password,
                    QueueName = AppSettings.MessageBroker.RabbitMQ.QueueName_FileDeleted,
                    AutomaticCreateEnabled = true,
                    ExchangeName           = AppSettings.MessageBroker.RabbitMQ.ExchangeName,
                    RoutingKey             = AppSettings.MessageBroker.RabbitMQ.RoutingKey_FileDeleted,
                });
            }

            if (AppSettings.MessageBroker.UsedKafka())
            {
                fileUploadedMessageQueueReceiver = new KafkaReceiver <FileUploadedEvent>(
                    AppSettings.MessageBroker.Kafka.BootstrapServers,
                    AppSettings.MessageBroker.Kafka.Topic_FileUploaded,
                    AppSettings.MessageBroker.Kafka.GroupId);

                fileDeletedMessageQueueReceiver = new KafkaReceiver <FileDeletedEvent>(
                    AppSettings.MessageBroker.Kafka.BootstrapServers,
                    AppSettings.MessageBroker.Kafka.Topic_FileDeleted,
                    AppSettings.MessageBroker.Kafka.GroupId);
            }

            if (AppSettings.MessageBroker.UsedAzureQueue())
            {
                fileUploadedMessageQueueReceiver = new AzureQueueReceiver <FileUploadedEvent>(
                    AppSettings.MessageBroker.AzureQueue.ConnectionString,
                    AppSettings.MessageBroker.AzureQueue.QueueName_FileUploaded);

                fileDeletedMessageQueueReceiver = new AzureQueueReceiver <FileDeletedEvent>(
                    AppSettings.MessageBroker.AzureQueue.ConnectionString,
                    AppSettings.MessageBroker.AzureQueue.QueueName_FileDeleted);
            }

            if (AppSettings.MessageBroker.UsedAzureServiceBus())
            {
                fileUploadedMessageQueueReceiver = new AzureServiceBusReceiver <FileUploadedEvent>(
                    AppSettings.MessageBroker.AzureServiceBus.ConnectionString,
                    AppSettings.MessageBroker.AzureServiceBus.QueueName_FileUploaded);

                fileDeletedMessageQueueReceiver = new AzureServiceBusReceiver <FileDeletedEvent>(
                    AppSettings.MessageBroker.AzureServiceBus.ConnectionString,
                    AppSettings.MessageBroker.AzureServiceBus.QueueName_FileDeleted);
            }

            var notification = new SignalRNotification();
            var endpoint     = $"{AppSettings.NotificationServer.Endpoint}/SimulatedLongRunningTaskHub";

            fileUploadedMessageQueueReceiver?.Receive(data =>
            {
                Thread.Sleep(5000); // simulate long running task

                string message = data.FileEntry.Id.ToString();

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"{AppSettings.MessageBroker.Provider} - File Uploaded", Message = message });
            });

            fileDeletedMessageQueueReceiver?.Receive(data =>
            {
                Thread.Sleep(5000); // simulate long running task

                string message = data.FileEntry.Id.ToString();

                notification.Send(endpoint, "SendTaskStatus", new { Step = $"{AppSettings.MessageBroker.Provider} - File Deleted", Message = message });
            });
        }