public override void MoveAllErrorMessagesToOriginQueue(string errorQueue)
        {
            try {
                var mgr = new ErrorManager(_connectionSettings[CS_CONNECTION_STRING] as string);

                mgr.ReturnAll(errorQueue, AzureServiceBusReceiver.GetAzureQueueCount(errorQueue));
            } catch (Exception e) {
                OnError("Failed to Return message", e);
            }
        }
        private void TestMessageBrokerReceivers()
        {
            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,
                });

                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,
                });
            }

            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 connection = new HubConnectionBuilder()
                             .WithUrl($"{AppSettings.NotificationServer.Endpoint}/SimulatedLongRunningTaskHub")
                             .AddMessagePackProtocol()
                             .Build();

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

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

                connection.StartAsync().GetAwaiter().GetResult();

                connection.InvokeAsync("SendTaskStatus", $"{AppSettings.MessageBroker.Provider} - File Uploaded", message);

                connection.StopAsync().GetAwaiter().GetResult();
            });

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

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

                connection.StartAsync().GetAwaiter().GetResult();

                connection.InvokeAsync("SendTaskStatus", $"{AppSettings.MessageBroker.Provider} - File Deleted", message);

                connection.StopAsync().GetAwaiter().GetResult();
            });
        }
예제 #3
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 });
            });
        }
        private static void Main(string[] args)
        {
            var connection = new HubConnectionBuilder()
                             .WithUrl("http://localhost:62710/SimulatedLongRunningTaskHub")
                             .AddMessagePackProtocol()
                             .Build();

            connection.On <string>("ReceiveTaskStatus", (message) => { Console.WriteLine(message); });
            connection.StartAsync().GetAwaiter().GetResult();

            var rabbitMQFileUploadedEventReceiver = new RabbitMQReceiver <FileUploadedEvent>(new RabbitMQReceiverOptions
            {
                HostName  = "localhost",
                UserName  = "******",
                Password  = "******",
                QueueName = "classifiedadds_fileuploaded",
            });

            rabbitMQFileUploadedEventReceiver.Receive(data =>
            {
                Console.WriteLine("RabbitMQ - File Uploaded: " + data.FileEntry.Id);
            });

            var rabbitMQFileDeletedEventReceiver = new RabbitMQReceiver <FileDeletedEvent>(new RabbitMQReceiverOptions
            {
                HostName  = "localhost",
                UserName  = "******",
                Password  = "******",
                QueueName = "classifiedadds_filedeleted",
            });

            rabbitMQFileDeletedEventReceiver.Receive(data =>
            {
                Console.WriteLine("RabbitMQ - File Deleted: " + data.FileEntry.Id);
            });

            var kafkaFileUploadedEventReceiver = new KafkaReceiver <FileUploadedEvent>("localhost:9092", "classifiedadds_fileuploaded", "classified");

            kafkaFileUploadedEventReceiver.Receive(data =>
            {
                Console.WriteLine("Kafka - File Uploaded: " + data.FileEntry.Id);
            });

            var kafkaFileDeletedEventReceiver = new KafkaReceiver <FileDeletedEvent>("localhost:9092", "classifiedadds_filedeleted", "classified");

            kafkaFileDeletedEventReceiver.Receive(data =>
            {
                Console.WriteLine("Kafka - File Deleted: " + data.FileEntry.Id);
            });

            var azureQueueFileUploadedEventReceiver = new AzureQueueReceiver <FileUploadedEvent>("DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net", "classifiedadds-fileuploaded");

            azureQueueFileUploadedEventReceiver.Receive(data =>
            {
                Console.WriteLine("AzureQueue - File Uploaded:" + data.FileEntry.Id);
            });

            var azureQueueFileDeletedEventReceiver = new AzureQueueReceiver <FileDeletedEvent>("DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net", "classifiedadds-filedeleted");

            azureQueueFileDeletedEventReceiver.Receive(data =>
            {
                Console.WriteLine("AzureQueue - File Deleted:" + data.FileEntry.Id);
            });

            var azureServiceBusFileUploadedEventReceiver = new AzureServiceBusReceiver <FileUploadedEvent>("Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=xxx;SharedAccessKey=xxx", "classifiedadds_fileuploaded");

            azureServiceBusFileUploadedEventReceiver.Receive(data =>
            {
                Console.WriteLine("AzureServiceBus - File Uploaded:" + data.FileEntry.Id);
            });

            var azureServiceBusFileDeletedEventReceiver = new AzureServiceBusReceiver <FileDeletedEvent>("Endpoint=sb://xxx.servicebus.windows.net/;SharedAccessKeyName=xxx;SharedAccessKey=xxx", "classifiedadds_filedeleted");

            azureServiceBusFileDeletedEventReceiver.Receive(data =>
            {
                Console.WriteLine("AzureServiceBus - File Deleted:" + data.FileEntry.Id);
            });

            Console.WriteLine("Listening...");
            Console.ReadLine();

            rabbitMQFileUploadedEventReceiver.Dispose();
            rabbitMQFileDeletedEventReceiver.Dispose();
        }
 public override Model.QueueFetchResult GetUnprocessedMessages(QueueFetchUnprocessedMessagesRequest req)
 {
     return(AzureServiceBusReceiver.GetUnprocessedMessages(req, _monitorQueues, x => PrepareQueueItemForAdd(x)));
 }