Example #1
0
        private void InitializeConnection()
        {
            try
            {
                Channel = RabbitChannelProvider.OpenChannelToHost(HostConfig);
                CreateExchange(_exchangeConfig);
                _sentMessageProperties             = Channel.CreateBasicProperties();
                _sentMessageProperties.ContentType = "text/plain";

                if (_messagesMustBeRouted)
                {
                    CreateQueue(_deadLetterQueueConfig);
                    _sentMessageProperties.DeliveryMode = 2; // 1 = Delivery is optional, 2 = Delivery is mandatory
                    Channel.BasicReturn += (sender, eventArgs) =>
                    {
                        Log.ErrorFormat(CultureInfo.InvariantCulture,
                                        "Message sent by publisher could not be routed. Message: \"{0}\"",
                                        Encoding.UTF8.GetString(eventArgs.Body));
                    };
                }
            }
            catch (BrokerUnreachableException ex)
            {
                throw new ConnectionException("Publisher was unable to connect to broker. Check that the broker is online and the publisher is configured correctly.", ex);
            }
        }
Example #2
0
 private void InitializeConnection()
 {
     try
     {
         Channel = RabbitChannelProvider.OpenChannelToHost(HostConfig);
         CreateQueue(_queueConfig);
         _consumer    = new QueueingBasicConsumer(Channel);
         _consumerTag = Channel.BasicConsume(_queueConfig.Name, _autoAckMessages, _consumer);
     }
     catch (BrokerUnreachableException ex)
     {
         throw new ConnectionException("Receiver was unable to connect to broker. Check that the broker is online and the receiver is configured correctly.", ex);
     }
 }