public Error MapMessageToErrorSchema(AggregateException exception, string correlationId, string messageType, string payload, MessageProperties properties, IDictionary<string, object> headers, MessageReceivedInfo info)
 {
     return new Error
     {
         errorDateTime = DateTime.Now,
         errorType = ErrorTypeEnum.ApplicationError,
         component = exception.InnerException.Source,
         server = Environment.MachineName,
         serviceName = messageType,
         summary = exception.InnerException.Message,
         detail = exception.InnerException.StackTrace,
         original = new OriginalDetails
         {
             jobId = correlationId,
             exchangeName = (info == null) ? string.Empty : info.Exchange,
             queueName = (info == null) ? string.Empty : info.Queue,
             payload = payload,
             correlationId = correlationId,
             routingKey = (info == null) ? string.Empty : info.RoutingKey,
             deliveryMode = properties.DeliveryMode.ToString(),
             headers = ConvertDictionaryToHeaderDetails(headers),
             headerProperties = ConvertMessagePropertiesToHeaderDetails(properties)
         }
     };
 }
        public IEnumerable<RecoveryMessage> GetMessagesFromQueue(IQueueOptions options)
        {
            using (var connection = RabbitConnection.FromOptions(options))
            using (var channel = connection.CreateModel())
            {
                try
                {
                    channel.QueueDeclarePassive(options.ErrorQueueName);
                }
                catch (OperationInterruptedException exception)
                {
                    _log.ErrorFormat("Error Occurred Getting a message from queue because {0}", exception, exception.Message);
                    yield break;
                }

                var count = 0;
                while (count++ < options.MaxNumberOfMessagesToRetrieve)
                {
                    var basicGetResult = channel.BasicGet(options.ErrorQueueName, noAck: options.RequireHandshake);
                    if (basicGetResult == null) break; // no more messages on the queue

                    var properties = new MessageProperties(basicGetResult.BasicProperties);
                    var info = new MessageReceivedInfo(
                        "recoveries",
                        basicGetResult.DeliveryTag,
                        basicGetResult.Redelivered,
                        basicGetResult.Exchange,
                        basicGetResult.RoutingKey,
                        options.ErrorQueueName);

                    yield return new RecoveryMessage(Encoding.UTF8.GetString(basicGetResult.Body), properties, info);
                }
            }
        }
        public RecoveryMessage(string body, MessageProperties properties, MessageReceivedInfo info)
        {
            if (body == null) throw new ArgumentNullException("body");
            if (properties == null) throw new ArgumentNullException("properties");
            if (info == null) throw new ArgumentNullException("info");

            Body = body;
            Properties = properties;
            Info = info;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="message"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public abstract Task ServiceMessageHandler(IMessage<NodeMessage> message, MessageReceivedInfo info);
Exemple #5
0
        public virtual void Consume(IQueue queue, Func <Byte[], MessageProperties, MessageReceivedInfo, Task> onMessage)
        {
            Preconditions.CheckNotNull(queue, "queue");
            Preconditions.CheckNotNull(onMessage, "onMessage");

            if (disposed)
            {
                throw new EasyNetQException("This bus has been disposed");
            }

            var newConsumerTag     = conventions.ConsumerTagConvention();
            var subscriptionAction = new SubscriptionAction(newConsumerTag, logger, queue.IsSingleUse, queue.IsExclusive);

            subscriptionAction.Action = (isNewConnection) =>
            {
                // recreate channel if current channel is no longer open or connection was dropped and reconnected (to survive server restart)
                if (subscriptionAction.Channel == null || subscriptionAction.Channel.IsOpen == false || isNewConnection)
                {
                    subscriptionAction.Channel = CreateChannel(queue);
                }

                var channel = subscriptionAction.Channel;

                channel.BasicQos(0, connectionConfiguration.PrefetchCount, false);

                var consumer = consumerFactory.CreateConsumer(subscriptionAction, channel, queue.IsSingleUse,
                                                              (consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body) =>
                {
                    var messageRecievedInfo = new MessageReceivedInfo
                    {
                        ConsumerTag = consumerTag,
                        DeliverTag  = deliveryTag,
                        Redelivered = redelivered,
                        Exchange    = exchange,
                        RoutingKey  = routingKey
                    };
                    var messsageProperties = new MessageProperties(properties);
                    return(onMessage(body, messsageProperties, messageRecievedInfo));
                });

                var cancelNotifications = consumer as IConsumerCancelNotifications;
                if (cancelNotifications != null)
                {
                    cancelNotifications.BasicCancel += OnBasicCancel;
                }

                channel.BasicConsume(
                    queue.Name,             // queue
                    NoAck,                  // noAck
                    consumer.ConsumerTag,   // consumerTag
                    consumer);              // consumer

                logger.DebugWrite("Declared Consumer. queue='{0}', consumer tag='{1}' prefetchcount={2}",
                                  queue.Name,
                                  consumer.ConsumerTag,
                                  connectionConfiguration.PrefetchCount);
            };



            AddSubscriptionAction(subscriptionAction);
        }
 /// <summary>
 /// receives incoming subscription topic messages for this service 
 /// </summary>
 /// <remarks>This handler needs to be enhanced with a list of handlers
 /// one for each distinct message managed by the coupled service.</remarks>
 /// <param name="message"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public override async Task ServiceMessageHandler(IMessage<NodeMessage> message, MessageReceivedInfo info)
 {
     this.m_node.ns.m_incomingETTotal += (int)(DateTime.Now.Ticks - message.Properties.Timestamp);      
 }