Example #1
0
 public Controller(IConnectionFactory sourceConnectionFactory, string queueName)
 {
     _queueName = queueName;
     _sourceConnection = new RabbitMqConnection(sourceConnectionFactory);
     _sourceChannel = new RabbitMqModel(_sourceConnection);
     _sourceChannel.QueueDeclarePassive(queueName);
     _messageSource = new ConfirmingGetter(_sourceChannel) { QueueName = queueName };
     _messagePublisher = new ConfirmingPublisher(_sourceChannel);
 }
Example #2
0
        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_sourceConnection != null)
                {
                    _sourceConnection.Dispose();
                    _sourceConnection = null;
                }

                if (_sourceChannel != null)
                {
                    _sourceChannel.Dispose();
                    _sourceChannel = null;
                }
            }
        }
        public async Task SendAndRecieveMessage()
        {
            var queueName = "testqueueB";
            var message = new RabbitMessage() { RoutingKey = queueName, Body = new byte[]{0,1,2,3,4}};
            var messageHandler = new TestMessageHandler();

            var connectionFactory = new ConnectionFactory
                                        {
                                            HostName = "mqBalancer",
                                            UserName = "******",
                                            Password = "******",
                                            RequestedHeartbeat = 5,
                                        };

            using (var connection = new RabbitMqConnection(connectionFactory))
            {
                using (var model = new RabbitMqModel(connection))
                {
                    model.QueueDeclare(queueName, false, true, false, new Dictionary<string, object>());

                    var consumer = model.HandleMessagesAsync(queueName);
                    var publisher = new ConfirmingPublisher(model);
                    await Task.Delay(TimeSpan.FromSeconds(1));
                    publisher.Publish(string.Empty, new[] { message });
                    await consumer.ConsumeMessages(messageHandler, CancellationToken.None);
                }
            }

            var result = messageHandler.LastMessage;
            Assert.That(result.Body, Is.EquivalentTo(message.Body));
        }