You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/03 17:56:32 UTC

svn commit: r992341 - /camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java

Author: davsclaus
Date: Fri Sep  3 15:56:31 2010
New Revision: 992341

URL: http://svn.apache.org/viewvc?rev=992341&view=rev
Log:
CAMEL-3102: JmsProducer in InOnly will lookup or create JMSReplyTo destination. This makes it easier to do fire and forget and have a JMSReplyTo header set for the receiver to reply sometime in the future.

Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=992341&r1=992340&r2=992341&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java Fri Sep  3 15:56:31 2010
@@ -231,7 +231,39 @@ public class JmsProducer extends Default
 
         MessageCreator messageCreator = new MessageCreator() {
             public Message createMessage(Session session) throws JMSException {
-                return endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
+                Message answer = endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
+
+                // if the binding did not create the reply to then we have to try to create it here
+                String replyTo = exchange.getIn().getHeader("JMSReplyTo", String.class);
+                if (replyTo != null && answer.getJMSReplyTo() == null) {
+                    Destination destination = null;
+                    // try using destination resolver to lookup the destination
+                    if (endpoint.getDestinationResolver() != null) {
+                        destination = endpoint.getDestinationResolver().resolveDestinationName(session, replyTo, endpoint.isPubSubDomain());
+                    }
+                    if (destination == null) {
+                        // okay then fallback and create the queue
+                        if (endpoint.isPubSubDomain()) {
+                            if (LOG.isDebugEnabled()) {
+                                LOG.debug("Creating JMSReplyTo topic: " + replyTo);
+                            }
+                            destination = session.createTopic(replyTo);
+                        } else {
+                            if (LOG.isDebugEnabled()) {
+                                LOG.debug("Creating JMSReplyTo queue: " + replyTo);
+                            }
+                            destination = session.createQueue(replyTo);
+                        }
+                    }
+                    if (destination != null) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Using JMSReplyTo destination: " + destination);
+                        }
+                        answer.setJMSReplyTo(destination);
+                    }
+                }
+
+                return answer;
             }
         };