List of usage examples for javax.jms Message setJMSReplyTo
void setJMSReplyTo(Destination replyTo) throws JMSException;
From source file:com.adaptris.core.jms.JmsProducerImpl.java
protected Message translate(AdaptrisMessage msg, Destination replyTo) throws JMSException { Message result = configuredMessageTranslator().translate(msg); configuredCorrelationIdSource().processCorrelationId(msg, result); if (replyTo != null) { // OpenJMS is fussy about null here result.setJMSReplyTo(replyTo); }/*from ww w.jav a 2 s . c o m*/ return result; }
From source file:org.apache.servicemix.jms.endpoints.JmsProviderEndpoint.java
/** * Process an InOnly or RobustInOnly exchange inside a JMS session. * This method delegates the JMS message creation to the marshaler and uses * the JMS template to send it. If the JMS destination that was used to send * the message is not the default one, it synchronously wait for the message * to come back using a JMS selector. Else, it just returns and the response * message will come back from the listener container. * * @param exchange// www . j a v a 2s . c o m * @param in * @param session * @throws Exception */ protected void processInOutInSession(final MessageExchange exchange, final NormalizedMessage in, final Session session) throws Exception { // Create destinations final Destination dest = getDestination(exchange, in, session); final Destination replyDest = getReplyDestination(exchange, in, session); // Create message and send it final Message sendJmsMsg = marshaler.createMessage(exchange, in, session); sendJmsMsg.setJMSReplyTo(replyDest); // handle correlation ID String correlationId = sendJmsMsg.getJMSMessageID() != null ? sendJmsMsg.getJMSMessageID() : exchange.getExchangeId(); sendJmsMsg.setJMSCorrelationID(correlationId); boolean asynchronous = replyDest.equals(replyDestination); if (asynchronous) { store.store(correlationId, exchange); } try { template.send(dest, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return sendJmsMsg; } }); } catch (Exception e) { if (asynchronous) { store.load(exchange.getExchangeId()); } throw e; } if (!asynchronous) { // Create selector String jmsId = sendJmsMsg.getJMSMessageID(); String selector = MSG_SELECTOR_START + jmsId + MSG_SELECTOR_END; // Receiving JMS Message, Creating and Returning NormalizedMessage out Message receiveJmsMsg = template.receiveSelected(replyDest, selector); if (receiveJmsMsg == null) { throw new IllegalStateException("Unable to receive response"); } NormalizedMessage out = exchange.getMessage("out"); if (out == null) { out = exchange.createMessage(); exchange.setMessage(out, "out"); } marshaler.populateMessage(receiveJmsMsg, exchange, out); boolean txSync = exchange.isTransacted() && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC)); if (txSync) { sendSync(exchange); } else { send(exchange); } } }
From source file:com.fusesource.forge.jmstest.tests.AsyncProducer.java
public void run() { try {/*from w ww .j a v a2 s. c o m*/ Connection conn = getConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (isExpectReply()) { Destination replyTo = getDestinationProvider().getDestination(session, getReplyDestination()); MessageConsumer consumer = session.createConsumer(replyTo); consumer.setMessageListener(this); } Destination dest = getDestinationProvider().getDestination(session, getDestinationName()); MessageProducer producer = session.createProducer(dest); producer.setDeliveryMode(getDeliveryMode().getCode()); getConnection().start(); LOG.info(">>Starting Message send loop"); while (!done.get()) { try { locallySent++; Destination replyDest = null; Message msg = getMessageFactory().createMessage(session); if (getMsgGroup() != null) { LOG.debug("Setting message group to : " + getMsgGroup()); msg.setStringProperty("JMSXGroupID", getMsgGroup()); if (getMessagesToSend() > 0) { if (locallySent == getMessagesToSend()) { LOG.debug("Closing message group: " + getMsgGroup()); msg.setIntProperty("JMSXGroupSeq", 0); } } } msg.setLongProperty("MsgNr", locallySent); if (isExpectReply()) { corrId = getReplyDestination() + "Seq-" + locallySent; msg.setStringProperty("JMSCorrelationID", corrId); replyDest = getDestinationProvider().getDestination(session, getReplyDestination()); msg.setJMSReplyTo(replyDest); receivedResponse = false; } long sendTime = System.currentTimeMillis(); producer.send(msg, deliveryMode.getCode(), 4, ttl); if (sent != null) { sent.incrementAndGet(); } done.set((getMessagesToSend() > 0) && ((locallySent) == getMessagesToSend())); if (isExpectReply()) { try { LOG.debug("Waiting for response ..."); synchronized (corrId) { try { if (getReplyTimeOut() > 0) { corrId.wait(getReplyTimeOut()); } else { corrId.wait(); } } catch (InterruptedException ie) { } if (receivedResponse) { long duration = System.currentTimeMillis() - sendTime; LOG.debug("Got response from peer in " + duration + " ms"); } else { LOG.error("Response not received within time frame..."); if (timeOuts != null) { timeOuts.incrementAndGet(); } } } } catch (Exception e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } if (sleep > 0L) { try { Thread.sleep(sleep); } catch (InterruptedException ie) { } } } catch (JMSException e) { if (exceptions != null) { exceptions.incrementAndGet(); } } } } catch (Exception e) { } finally { try { closeConnection(); } catch (Throwable e) { } } LOG.info(">>MessageSender done...(" + sent + ")"); }
From source file:hermes.impl.DefaultXMLHelper.java
public Message createMessage(MessageFactory hermes, XMLMessage message) throws JMSException, IOException, ClassNotFoundException, DecoderException { try {/*from ww w. j a va 2 s.co m*/ Message rval = hermes.createMessage(); if (message instanceof XMLTextMessage) { rval = hermes.createTextMessage(); XMLTextMessage textMessage = (XMLTextMessage) message; TextMessage textRval = (TextMessage) rval; if (BASE64_CODEC.equals(textMessage.getCodec())) { byte[] bytes = base64EncoderTL.get().decode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof XMLMapMessage) { rval = hermes.createMapMessage(); XMLMapMessage mapMessage = (XMLMapMessage) message; MapMessage mapRval = (MapMessage) rval; for (Iterator iter = mapMessage.getBodyProperty().iterator(); iter.hasNext();) { final Property property = (Property) iter.next(); if (property.getValue() == null) { mapRval.setObject(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { mapRval.setString(property.getName(), property.getValue()); } else if (property.getType().equals(Long.class.getName())) { mapRval.setLong(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { mapRval.setDouble(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { mapRval.setBoolean(property.getName(), Boolean.getBoolean(property.getValue())); } else if (property.getType().equals(Character.class.getName())) { mapRval.setChar(property.getName(), property.getValue().charAt(0)); } else if (property.getType().equals(Short.class.getName())) { mapRval.setShort(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { mapRval.setInt(property.getName(), Integer.parseInt(property.getValue())); } } } else if (message instanceof XMLBytesMessage) { rval = hermes.createBytesMessage(); XMLBytesMessage bytesMessage = (XMLBytesMessage) message; BytesMessage bytesRval = (BytesMessage) rval; bytesRval.writeBytes(base64EncoderTL.get().decode(bytesMessage.getBytes().getBytes())); } else if (message instanceof XMLObjectMessage) { rval = hermes.createObjectMessage(); XMLObjectMessage objectMessage = (XMLObjectMessage) message; ObjectMessage objectRval = (ObjectMessage) rval; ByteArrayInputStream bistream = new ByteArrayInputStream( base64EncoderTL.get().decode(objectMessage.getObject().getBytes())); ObjectInputStream oistream = new ObjectInputStream(bistream); objectRval.setObject((Serializable) oistream.readObject()); } // // JMS Header properties try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error("unable to set JMSDeliveryMode to " + message.getJMSDeliveryMode() + ": " + ex.getMessage()); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error("unable to set JMSMessageID: " + ex.getMessage(), ex); } try { if (message.getJMSExpiration() != null) { rval.setJMSExpiration(message.getJMSExpiration()); } } catch (JMSException ex) { log.error("unable to set JMSExpiration: " + ex.getMessage(), ex); } try { if (message.getJMSPriority() != null) { rval.setJMSPriority(message.getJMSPriority()); } } catch (JMSException ex) { log.error("unable to set JMSPriority: " + ex.getMessage(), ex); } try { if (message.getJMSTimestamp() != null) { rval.setJMSTimestamp(message.getJMSTimestamp()); } } catch (JMSException ex) { log.error("unable to set JMSTimestamp:" + ex.getMessage(), ex); } if (message.getJMSCorrelationID() != null) { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } if (message.getJMSReplyTo() != null && !message.getJMSReplyTo().equals("null")) { rval.setJMSReplyTo(hermes.getDestination(message.getJMSReplyTo(), Domain.getDomain(message.getJMSReplyToDomain()))); } if (message.getJMSType() != null) { rval.setJMSType(message.getJMSType()); } if (message.getJMSDestination() != null) { if (message.isFromQueue()) { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.QUEUE)); } else { rval.setJMSDestination(hermes.getDestination(message.getJMSDestination(), Domain.TOPIC)); } } for (Iterator iter = message.getHeaderProperty().iterator(); iter.hasNext();) { Property property = (Property) iter.next(); if (property.getValue() == null) { rval.setObjectProperty(property.getName(), null); } else if (property.getType().equals(String.class.getName())) { rval.setStringProperty(property.getName(), StringEscapeUtils.unescapeXml(property.getValue())); } else if (property.getType().equals(Long.class.getName())) { rval.setLongProperty(property.getName(), Long.parseLong(property.getValue())); } else if (property.getType().equals(Double.class.getName())) { rval.setDoubleProperty(property.getName(), Double.parseDouble(property.getValue())); } else if (property.getType().equals(Boolean.class.getName())) { rval.setBooleanProperty(property.getName(), Boolean.parseBoolean(property.getValue())); } else if (property.getType().equals(Short.class.getName())) { rval.setShortProperty(property.getName(), Short.parseShort(property.getValue())); } else if (property.getType().equals(Integer.class.getName())) { rval.setIntProperty(property.getName(), Integer.parseInt(property.getValue())); } } return rval; } catch (NamingException e) { throw new HermesException(e); } }
From source file:nl.nn.adapterframework.jms.JmsSender.java
public String sendMessage(String correlationID, String message, ParameterResolutionContext prc, String soapHeader) throws SenderException, TimeOutException { Session s = null;//from w w w . j a v a2 s . co m MessageProducer mp = null; ParameterValueList pvl = null; if (prc != null && paramList != null) { try { pvl = prc.getValues(paramList); } catch (ParameterException e) { throw new SenderException(getLogPrefix() + "cannot extract parameters", e); } } if (isSoap()) { if (soapHeader == null) { if (pvl != null && StringUtils.isNotEmpty(getSoapHeaderParam())) { ParameterValue soapHeaderParamValue = pvl.getParameterValue(getSoapHeaderParam()); if (soapHeaderParamValue == null) { log.warn("no SoapHeader found using parameter [" + getSoapHeaderParam() + "]"); } else { soapHeader = soapHeaderParamValue.asStringValue(""); } } } message = soapWrapper.putInEnvelope(message, getEncodingStyleURI(), getServiceNamespaceURI(), soapHeader); if (log.isDebugEnabled()) log.debug(getLogPrefix() + "correlationId [" + correlationID + "] soap message [" + message + "]"); } try { s = createSession(); mp = getMessageProducer(s, getDestination(prc)); Destination replyQueue = null; // create message Message msg = createTextMessage(s, correlationID, message); if (getMessageType() != null) { msg.setJMSType(getMessageType()); } if (getDeliveryModeInt() > 0) { msg.setJMSDeliveryMode(getDeliveryModeInt()); mp.setDeliveryMode(getDeliveryModeInt()); } if (getPriority() >= 0) { msg.setJMSPriority(getPriority()); mp.setPriority(getPriority()); } // set properties if (pvl != null) { setProperties(msg, pvl); } if (replyToName != null) { replyQueue = getDestination(replyToName); } else { if (isSynchronous()) { replyQueue = getMessagingSource().getDynamicReplyQueue(s); } } if (replyQueue != null) { msg.setJMSReplyTo(replyQueue); if (log.isDebugEnabled()) log.debug("replyTo set to queue [" + replyQueue.toString() + "]"); } // send message send(mp, msg); if (log.isDebugEnabled()) { log.debug("[" + getName() + "] " + "sent message [" + message + "] " + "to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : "")); } else { if (log.isInfoEnabled()) { log.info("[" + getName() + "] " + "sent message to [" + mp.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "using deliveryMode [" + getDeliveryMode() + "] " + ((replyToName != null) ? "replyTo [" + replyToName + "]" : "")); } } if (isSynchronous()) { String replyCorrelationId = null; if (replyToName != null) { if ("CORRELATIONID".equalsIgnoreCase(getLinkMethod())) { replyCorrelationId = correlationID; } else if ("CORRELATIONID_FROM_MESSAGE".equalsIgnoreCase(getLinkMethod())) { replyCorrelationId = msg.getJMSCorrelationID(); } else { replyCorrelationId = msg.getJMSMessageID(); } } if (log.isDebugEnabled()) log.debug("[" + getName() + "] start waiting for reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] for [" + getReplyTimeout() + "] ms"); MessageConsumer mc = getMessageConsumerForCorrelationId(s, replyQueue, replyCorrelationId); try { Message rawReplyMsg = mc.receive(getReplyTimeout()); if (rawReplyMsg == null) { throw new TimeOutException("did not receive reply on [" + replyQueue + "] requestMsgId [" + msg.getJMSMessageID() + "] replyCorrelationId [" + replyCorrelationId + "] within [" + getReplyTimeout() + "] ms"); } return getStringFromRawMessage(rawReplyMsg, prc != null ? prc.getSession() : null, isSoap(), getReplySoapHeaderSessionKey(), soapWrapper); } finally { if (mc != null) { try { mc.close(); } catch (JMSException e) { log.warn("JmsSender [" + getName() + "] got exception closing message consumer for reply", e); } } } } return msg.getJMSMessageID(); } catch (JMSException e) { throw new SenderException(e); } catch (IOException e) { throw new SenderException(e); } catch (NamingException e) { throw new SenderException(e); } catch (DomBuilderException e) { throw new SenderException(e); } catch (TransformerException e) { throw new SenderException(e); } catch (JmsException e) { throw new SenderException(e); } finally { if (mp != null) { try { mp.close(); } catch (JMSException e) { log.warn("JmsSender [" + getName() + "] got exception closing message producer", e); } } closeSession(s); } }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * Set the JMS ReplyTo for the message/*from ww w. ja va 2 s . co m*/ * * @param replyDestination the JMS Destination where the reply is expected * @param session the session to use to create a temp Queue if a response is expected * but a Destination has not been specified * @param message the JMS message where the final Destinatio would be set as the JMS ReplyTo * @return the JMS ReplyTo Destination for the message */ public static Destination setReplyDestination(Destination replyDestination, Session session, Message message) { if (replyDestination == null) { try { // create temporary queue to receive the reply replyDestination = createTemporaryDestination(session); } catch (JMSException e) { handleException("Error creating temporary queue for response", e); } } try { message.setJMSReplyTo(replyDestination); } catch (JMSException e) { log.warn("Error setting JMS ReplyTo destination to : " + replyDestination, e); } if (log.isDebugEnabled()) { try { assert replyDestination != null; log.debug("Expecting a response to JMS Destination : " + (replyDestination instanceof Queue ? ((Queue) replyDestination).getQueueName() : ((Topic) replyDestination).getTopicName())); } catch (JMSException ignore) { } } return replyDestination; }
From source file:org.apache.camel.component.jms.JmsBinding.java
public void appendJmsProperty(Message jmsMessage, Exchange exchange, org.apache.camel.Message in, String headerName, Object headerValue) throws JMSException { if (isStandardJMSHeader(headerName)) { if (headerName.equals("JMSCorrelationID")) { jmsMessage.setJMSCorrelationID(ExchangeHelper.convertToType(exchange, String.class, headerValue)); } else if (headerName.equals("JMSReplyTo") && headerValue != null) { if (headerValue instanceof String) { // if the value is a String we must normalize it first headerValue = normalizeDestinationName((String) headerValue); }//w w w .j av a2 s . co m jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange, Destination.class, headerValue)); } else if (headerName.equals("JMSType")) { jmsMessage.setJMSType(ExchangeHelper.convertToType(exchange, String.class, headerValue)); } else if (headerName.equals("JMSPriority")) { jmsMessage.setJMSPriority(ExchangeHelper.convertToType(exchange, Integer.class, headerValue)); } else if (headerName.equals("JMSDeliveryMode")) { Integer deliveryMode = ExchangeHelper.convertToType(exchange, Integer.class, headerValue); jmsMessage.setJMSDeliveryMode(deliveryMode); jmsMessage.setIntProperty(JmsConstants.JMS_DELIVERY_MODE, deliveryMode); } else if (headerName.equals("JMSExpiration")) { jmsMessage.setJMSExpiration(ExchangeHelper.convertToType(exchange, Long.class, headerValue)); } else if (LOG.isTraceEnabled()) { // The following properties are set by the MessageProducer: // JMSDestination // The following are set on the underlying JMS provider: // JMSMessageID, JMSTimestamp, JMSRedelivered // log at trace level to not spam log LOG.trace("Ignoring JMS header: " + headerName + " with value: " + headerValue); } } else if (shouldOutputHeader(in, headerName, headerValue, exchange)) { // only primitive headers and strings is allowed as properties // see message properties: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html Object value = getValidJMSHeaderValue(headerName, headerValue); if (value != null) { // must encode to safe JMS header name before setting property on jmsMessage String key = jmsKeyFormatStrategy.encodeKey(headerName); // set the property JmsMessageHelper.setProperty(jmsMessage, key, value); } else if (LOG.isDebugEnabled()) { // okay the value is not a primitive or string so we cannot sent it over the wire LOG.debug("Ignoring non primitive header: " + headerName + " of class: " + headerValue.getClass().getName() + " with value: " + headerValue); } } }
From source file:org.apache.camel.component.jms.JmsProducer.java
protected boolean processInOut(final Exchange exchange, final AsyncCallback callback) { final org.apache.camel.Message in = exchange.getIn(); String destinationName = in.getHeader(JmsConstants.JMS_DESTINATION_NAME, String.class); // remove the header so it wont be propagated in.removeHeader(JmsConstants.JMS_DESTINATION_NAME); if (destinationName == null) { destinationName = endpoint.getDestinationName(); }/* ww w. j av a2 s. com*/ Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION, Destination.class); // remove the header so it wont be propagated in.removeHeader(JmsConstants.JMS_DESTINATION); if (destination == null) { destination = endpoint.getDestination(); } if (destination != null) { // prefer to use destination over destination name destinationName = null; } initReplyManager(); // when using message id as correlation id, we need at first to use a provisional correlation id // which we then update to the real JMSMessageID when the message has been sent // this is done with the help of the MessageSentCallback final boolean msgIdAsCorrId = endpoint.getConfiguration().isUseMessageIDAsCorrelationID(); final String provisionalCorrelationId = msgIdAsCorrId ? getUuidGenerator().generateUuid() : null; MessageSentCallback messageSentCallback = null; if (msgIdAsCorrId) { messageSentCallback = new UseMessageIdAsCorrelationIdMessageSentCallback(replyManager, provisionalCorrelationId, endpoint.getRequestTimeout()); } final ValueHolder<MessageSentCallback> sentCallback = new ValueHolder<MessageSentCallback>( messageSentCallback); final String originalCorrelationId = in.getHeader("JMSCorrelationID", String.class); if (originalCorrelationId == null && !msgIdAsCorrId) { in.setHeader("JMSCorrelationID", getUuidGenerator().generateUuid()); } MessageCreator messageCreator = new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message message = endpoint.getBinding().makeJmsMessage(exchange, in, session, null); // get the reply to destination to be used from the reply manager Destination replyTo = replyManager.getReplyTo(); if (replyTo == null) { throw new RuntimeExchangeException("Failed to resolve replyTo destination", exchange); } message.setJMSReplyTo(replyTo); replyManager.setReplyToSelectorHeader(in, message); String correlationId = determineCorrelationId(message, provisionalCorrelationId); replyManager.registerReply(replyManager, exchange, callback, originalCorrelationId, correlationId, endpoint.getRequestTimeout()); return message; } }; doSend(true, destinationName, destination, messageCreator, sentCallback.get()); // after sending then set the OUT message id to the JMSMessageID so its identical setMessageId(exchange); // continue routing asynchronously (reply will be processed async when its received) return false; }
From source file:org.apache.camel.component.jms.JmsProducer.java
protected boolean processInOnly(final Exchange exchange, final AsyncCallback callback) { final org.apache.camel.Message in = exchange.getIn(); String destinationName = in.getHeader(JmsConstants.JMS_DESTINATION_NAME, String.class); if (destinationName != null) { // remove the header so it wont be propagated in.removeHeader(JmsConstants.JMS_DESTINATION_NAME); }/* www . j a va 2s. c o m*/ if (destinationName == null) { destinationName = endpoint.getDestinationName(); } Destination destination = in.getHeader(JmsConstants.JMS_DESTINATION, Destination.class); if (destination != null) { // remove the header so it wont be propagated in.removeHeader(JmsConstants.JMS_DESTINATION); } if (destination == null) { destination = endpoint.getDestination(); } if (destination != null) { // prefer to use destination over destination name destinationName = null; } final String to = destinationName != null ? destinationName : "" + destination; MessageCreator messageCreator = new MessageCreator() { public Message createMessage(Session session) throws JMSException { Message answer = endpoint.getBinding().makeJmsMessage(exchange, in, session, null); // when in InOnly mode the JMSReplyTo is a bit complicated // we only want to set the JMSReplyTo on the answer if // there is a JMSReplyTo from the header/endpoint and // we have been told to preserveMessageQos Object jmsReplyTo = answer.getJMSReplyTo(); if (endpoint.isDisableReplyTo()) { // honor disable reply to configuration if (LOG.isDebugEnabled()) { LOG.debug("ReplyTo is disabled on endpoint: " + endpoint); } answer.setJMSReplyTo(null); } else { // if the binding did not create the reply to then we have to try to create it here if (jmsReplyTo == null) { // prefer reply to from header over endpoint configured jmsReplyTo = exchange.getIn().getHeader("JMSReplyTo", String.class); if (jmsReplyTo == null) { jmsReplyTo = endpoint.getReplyTo(); } } } // we must honor these special flags to preserve QoS // as we are not OUT capable and thus do not expect a reply, and therefore // the consumer of this message should not return a reply so we remove it // unless we use preserveMessageQos=true to tell that we still want to use JMSReplyTo if (jmsReplyTo != null && !(endpoint.isPreserveMessageQos() || endpoint.isExplicitQosEnabled())) { // log at debug what we are doing, as higher level may cause noise in production logs // this behavior is also documented at the camel website if (LOG.isDebugEnabled()) { LOG.debug("Disabling JMSReplyTo: " + jmsReplyTo + " for destination: " + to + ". Use preserveMessageQos=true to force Camel to keep the JMSReplyTo on endpoint: " + endpoint); } jmsReplyTo = null; } // the reply to is a String, so we need to look up its Destination instance // and if needed create the destination using the session if needed to if (jmsReplyTo != null && jmsReplyTo instanceof String) { // must normalize the destination name String replyTo = normalizeDestinationName((String) jmsReplyTo); // we need to null it as we use the String to resolve it as a Destination instance jmsReplyTo = null; // try using destination resolver to lookup the destination if (endpoint.getDestinationResolver() != null) { jmsReplyTo = endpoint.getDestinationResolver().resolveDestinationName(session, replyTo, endpoint.isPubSubDomain()); } if (jmsReplyTo == null) { // okay then fallback and create the queue if (endpoint.isPubSubDomain()) { if (LOG.isDebugEnabled()) { LOG.debug("Creating JMSReplyTo topic: " + replyTo); } jmsReplyTo = session.createTopic(replyTo); } else { if (LOG.isDebugEnabled()) { LOG.debug("Creating JMSReplyTo queue: " + replyTo); } jmsReplyTo = session.createQueue(replyTo); } } } // set the JMSReplyTo on the answer if we are to use it Destination replyTo = null; if (jmsReplyTo instanceof Destination) { replyTo = (Destination) jmsReplyTo; } if (replyTo != null) { if (LOG.isDebugEnabled()) { LOG.debug("Using JMSReplyTo destination: " + replyTo); } answer.setJMSReplyTo(replyTo); } else { // do not use JMSReplyTo answer.setJMSReplyTo(null); } return answer; } }; doSend(false, destinationName, destination, messageCreator, null); // after sending then set the OUT message id to the JMSMessageID so its identical setMessageId(exchange); // we are synchronous so return true callback.done(true); return true; }
From source file:org.apache.synapse.transport.jms.JMSUtils.java
/** * Set the JMS ReplyTo for the message/* w ww . j a va2 s .c o m*/ * * @param replyDestination the JMS Destination where the reply is expected * @param session the session to use to create a temp Queue if a response is expected * but a Destination has not been specified * @param message the JMS message where the final Destinatio would be set as the JMS ReplyTo * @return the JMS ReplyTo Destination for the message */ public static Destination setReplyDestination(Destination replyDestination, Session session, Message message) { if (replyDestination == null) { try { // create temporary queue to receive the reply replyDestination = createTemporaryDestination(session); } catch (JMSException e) { handleException("Error creating temporary queue for response"); } } try { message.setJMSReplyTo(replyDestination); } catch (JMSException e) { log.warn("Error setting JMS ReplyTo destination to : " + replyDestination, e); } if (log.isDebugEnabled()) { try { log.debug("Expecting a response to JMS Destination : " + (replyDestination instanceof Queue ? ((Queue) replyDestination).getQueueName() : ((Topic) replyDestination).getTopicName())); } catch (JMSException ignore) { } } return replyDestination; }