Esempio n. 1
0
        public Conventions()
        {
            // Establish default conventions.
            ExchangeNamingConvention = TypeNameSerializer.Serialize;
            TopicNamingConvention    = messageType => "";
            QueueNamingConvention    =
                (messageType, subscriptionId) =>
            {
                var typeName = TypeNameSerializer.Serialize(messageType);
                return(string.Format("{0}_{1}", typeName, subscriptionId));
            };
            RpcRoutingKeyNamingConvention = TypeNameSerializer.Serialize;

            ErrorQueueNamingConvention    = () => "EasyNetQ_Default_Error_Queue";
            ErrorExchangeNamingConvention = (originalRoutingKey) => "ErrorExchange_" + originalRoutingKey;
            RpcExchangeNamingConvention   = () => "easy_net_q_rpc";
        }
Esempio n. 2
0
        public virtual void HandleConsumerError(BasicDeliverEventArgs devliverArgs, Exception exception)
        {
            try
            {
                Connect();

                using (var model = connection.CreateModel())
                {
                    var errorExchange = DeclareErrorExchangeQueueStructure(model, devliverArgs.RoutingKey);

                    var messageBody = CreateErrorMessage(devliverArgs, exception);
                    var properties  = model.CreateBasicProperties();
                    properties.SetPersistent(true);
                    properties.Type = TypeNameSerializer.Serialize(typeof(Error));

                    model.BasicPublish(errorExchange, devliverArgs.RoutingKey, properties, messageBody);
                }
            }
            catch (BrokerUnreachableException)
            {
                // thrown if the broker is unreachable during initial creation.
                logger.Error("EasyNetQ Consumer Error Handler cannot connect to Broker\n" +
                             CreateConnectionCheckMessage());
            }
            catch (OperationInterruptedException interruptedException)
            {
                // thrown if the broker connection is broken during declare or publish.
                logger.Error("EasyNetQ Consumer Error Handler: Broker connection was closed while attempting to publish Error message.\n" +
                             string.Format("Message was: '{0}'\n", interruptedException.Message) +
                             CreateConnectionCheckMessage());
            }
            catch (Exception unexpecctedException)
            {
                // Something else unexpected has gone wrong :(
                logger.Error("EasyNetQ Consumer Error Handler: Failed to publish error message\nException is:\n"
                             + unexpecctedException);
            }
        }