public void NoReplyToAndNoDefault() { QueueChannel requestChannel = new QueueChannel(); StartBackgroundReplier(requestChannel); ChannelPublishingJmsMessageListener listener = new ChannelPublishingJmsMessageListener(); listener.ExpectReply = true; listener.RequestChannel = requestChannel; listener.MessageConverter = new TestMessageConverter(); Apache.NMS.IMessage nmsMessage = session.CreateTextMessage("test"); listener.AfterPropertiesSet(); listener.OnMessage(nmsMessage, session); }
/// <summary> /// Determine the reply destination for the given message /// </summary> /// <remarks> /// This implementation first checks the NMS ReplyTo Destination of the supplied request message; if that is /// not null, it is returned; if it is null, then the return value of <see cref="ResolveDefaultReplyDestination"/> /// is returned; ift his too is null, then an <see cref="InvalidDestinationException"/> if thrown /// </remarks> /// <param name="request">The original incoming NMS message.</param> /// <param name="session">The NMS session to operate on.</param> /// <returns>The reply destination (never null).</returns> /// <exception cref="InvalidDestinationException">If no <see cref="IDestination"/> can be determined. /// </exception> /// <seealso cref="DefaultReplyDestination"/> private IDestination GetReplyDestination(Apache.NMS.IMessage request, Apache.NMS.ISession session) { IDestination replyTo = request.NMSReplyTo; if (replyTo == null) { replyTo = ResolveDefaultReplyDestination(session); if (replyTo == null) { throw new InvalidDestinationException("Cannot determine reply destination: " + "Request message does not contain reply-to destination, and no default reply destination set."); } } return(replyTo); }
public void OnMessage(IMessage nmsMessage, ISession session) { object obj = messageConverter.FromMessage(nmsMessage); Spring.Integration.Core.IMessage requestMessage = obj as Spring.Integration.Core.IMessage; if (requestMessage == null) { requestMessage = MessageBuilder.WithPayload(obj).Build(); } if (!expectReply) { bool sent = channelTemplate.Send(requestMessage); if (!sent) { throw new MessageDeliveryException(requestMessage, "failed to send Message to request channel"); } } else { Spring.Integration.Core.IMessage replyMessage = channelTemplate.SendAndReceive(requestMessage); if (replyMessage != null) { IDestination destination = GetReplyDestination(nmsMessage, session); Apache.NMS.IMessage nmsReply = messageConverter.ToMessage(replyMessage, session); if (nmsReply.NMSCorrelationID != null) { nmsReply.NMSCorrelationID = nmsMessage.NMSMessageId; } Apache.NMS.IMessageProducer producer = session.CreateProducer(destination); try { producer.Send(nmsReply); } finally { producer.Close(); } } } }