Exemple #1
0
        private void RpcConsumerReplyReceived(BasicDeliverEventArgs deliveryEvent)
        {
            ValidateRpcReply(deliveryEvent);

            // Determine the command type based on the type name stored in basic properties.  NOTE: a command type name is
            // just a value used to identify the type used to determine the C# class type on the receiving end corresponding
            // to the type on the caller's end.  They may or may not be the same physical C# type.
            string typeName    = deliveryEvent.BasicProperties.Type;
            Type   commandType = _brokerState.RpcTypes[typeName];

            // Dispatch the message the handler to obtain the result.
            MessageDispatchInfo dispatcher = _messagingModule.GetInProcessCommandDispatcher(commandType);
            IMessage            message    = _serializationMgr.Deserialize(commandType, deliveryEvent);
            object result = null;

            try
            {
                result = _messagingModule.InvokeDispatcherAsync(dispatcher, message).Result;

                // Publish the reply back to the publisher that made the request on the
                // queue specified by them in the message header on a new channel.
                PublishConsumerReply(result, deliveryEvent.BasicProperties);
            }
            catch (AggregateException ex)
            {
                PublishConsumerExceptionReply(ex.InnerException, deliveryEvent.BasicProperties);
            }
            catch (Exception ex)
            {
                PublishConsumerExceptionReply(ex, deliveryEvent.BasicProperties);
            }
        }
Exemple #2
0
        // Deserialize the message into the type associated with the message dispatch
        // metadata and delegates to the messaging module to dispatch the message to
        // consumer handlers.
        private void MessageReceived(MessageConsumer messageConsumer, IModel channel, BasicDeliverEventArgs deliveryEvent)
        {
            IMessage message = _serializationMgr.Deserialize(messageConsumer.DispatchInfo.MessageType, deliveryEvent);

            message.SetAcknowledged(false);

            LogReceivedExchangeMessage(message, messageConsumer);

            // Delegate to the Messaging Module to dispatch the message to queue consumer.
            Task <object> futureResult = _messagingModule.InvokeDispatcherAsync(
                messageConsumer.DispatchInfo, message);

            futureResult.Wait();

            if (!messageConsumer.QueueSettings.IsNoAck)
            {
                HandleAcknowledgeMessage(message, channel, deliveryEvent);
            }

            HandleRejectedMessage(message, channel, deliveryEvent);
        }