List of usage examples for org.springframework.jms.support JmsUtils closeMessageProducer
public static void closeMessageProducer(@Nullable MessageProducer producer)
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
/** * Creates the MessageConsumer before sending the request Message since we do not need any correlation. *///from www .java2 s .co m private javax.jms.Message doSendAndReceiveWithTemporaryReplyToDestination(Destination requestDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { MessageProducer messageProducer = null; MessageConsumer messageConsumer = null; try { messageProducer = session.createProducer(requestDestination); messageConsumer = session.createConsumer(replyTo); this.sendRequestMessage(jmsRequest, messageProducer, priority); return this.receiveReplyMessage(messageConsumer); } finally { JmsUtils.closeMessageProducer(messageProducer); JmsUtils.closeMessageConsumer(messageConsumer); } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
/** * Creates the MessageConsumer after sending the request Message since we need * the MessageID for correlation with a MessageSelector. *///from w ww . ja v a 2s . c o m private javax.jms.Message doSendAndReceiveWithMessageIdCorrelation(Destination requestDestination, javax.jms.Message jmsRequest, Destination replyTo, Session session, int priority) throws JMSException { if (replyTo instanceof Topic && logger.isWarnEnabled()) { logger.warn( "Relying on the MessageID for correlation is not recommended when using a Topic as the replyTo Destination " + "because that ID can only be provided to a MessageSelector after the request Message has been sent thereby " + "creating a race condition where a fast response might be sent before the MessageConsumer has been created. " + "Consider providing a value to the 'correlationKey' property of this gateway instead. Then the MessageConsumer " + "will be created before the request Message is sent."); } MessageProducer messageProducer = null; try { messageProducer = session.createProducer(requestDestination); this.sendRequestMessage(jmsRequest, messageProducer, priority); String messageId = jmsRequest.getJMSMessageID().replaceAll("'", "''"); String messageSelector = "JMSCorrelationID = '" + messageId + "'"; return retryableReceiveReply(session, replyTo, messageSelector); } finally { JmsUtils.closeMessageProducer(messageProducer); } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
private Object doSendAndReceiveAsync(Destination requestDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { String correlationId = null;//from w ww .java2s. c o m MessageProducer messageProducer = null; try { messageProducer = session.createProducer(requestDestination); correlationId = this.gatewayCorrelation + "_" + Long.toString(this.correlationId.incrementAndGet()); if (this.correlationKey.equals("JMSCorrelationID")) { jmsRequest.setJMSCorrelationID(correlationId); } else { jmsRequest.setStringProperty(this.correlationKey, correlationId); /* * Remove any existing correlation id that was mapped from the inbound message * (it will be restored in the reply by normal ARPMH header processing). */ jmsRequest.setJMSCorrelationID(null); } LinkedBlockingQueue<javax.jms.Message> replyQueue = null; if (logger.isDebugEnabled()) { logger.debug(this.getComponentName() + " Sending message with correlationId " + correlationId); } SettableListenableFuture<AbstractIntegrationMessageBuilder<?>> future = null; boolean async = isAsync(); if (!async) { replyQueue = new LinkedBlockingQueue<javax.jms.Message>(1); this.replies.put(correlationId, replyQueue); } else { future = createFuture(correlationId); } this.sendRequestMessage(jmsRequest, messageProducer, priority); if (async) { return future; } else { return obtainReplyFromContainer(correlationId, replyQueue); } } finally { JmsUtils.closeMessageProducer(messageProducer); if (correlationId != null && !isAsync()) { this.replies.remove(correlationId); } } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
private javax.jms.Message doSendAndReceiveAsyncDefaultCorrelation(Destination requestDestination, javax.jms.Message jmsRequest, Session session, int priority) throws JMSException { String correlationId = null;//from ww w . ja v a 2s. c o m MessageProducer messageProducer = null; try { messageProducer = session.createProducer(requestDestination); LinkedBlockingQueue<javax.jms.Message> replyQueue = new LinkedBlockingQueue<javax.jms.Message>(1); this.sendRequestMessage(jmsRequest, messageProducer, priority); correlationId = jmsRequest.getJMSMessageID(); if (logger.isDebugEnabled()) { logger.debug(this.getComponentName() + " Sent message with correlationId " + correlationId); } this.replies.put(correlationId, replyQueue); /* * Check to see if the reply arrived before we obtained the correlationId */ synchronized (this.earlyOrLateReplies) { TimedReply timedReply = this.earlyOrLateReplies.remove(correlationId); if (timedReply != null) { if (logger.isDebugEnabled()) { logger.debug("Found early reply with correlationId " + correlationId); } replyQueue.add(timedReply.getReply()); } } return obtainReplyFromContainer(correlationId, replyQueue); } finally { JmsUtils.closeMessageProducer(messageProducer); if (correlationId != null) { this.replies.remove(correlationId); } } }
From source file:org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener.java
/** * Send the given response message to the given destination. * @param response the JMS message to send * @param destination the JMS destination to send to * @param session the JMS session to operate on * @throws JMSException if thrown by JMS API methods * @see #postProcessProducer/*from w ww . ja va 2 s .c o m*/ * @see javax.jms.Session#createProducer * @see javax.jms.MessageProducer#send */ protected void sendResponse(Session session, Destination destination, Message response) throws JMSException { MessageProducer producer = session.createProducer(destination); try { postProcessProducer(producer, response); QosSettings settings = getResponseQosSettings(); if (settings != null) { producer.send(response, settings.getDeliveryMode(), settings.getPriority(), settings.getTimeToLive()); } else { producer.send(response); } } finally { JmsUtils.closeMessageProducer(producer); } }
From source file:org.springframework.jms.listener.adapter.MessageListenerAdapter.java
/** * Send the given response message to the given destination. * @param response the JMS message to send * @param destination the JMS destination to send to * @param session the JMS session to operate on * @throws JMSException if thrown by JMS API methods * @see #postProcessProducer/*ww w .j a v a 2 s .c o m*/ * @see javax.jms.Session#createProducer * @see javax.jms.MessageProducer#send */ protected void sendResponse(Session session, Destination destination, Message response) throws JMSException { MessageProducer producer = session.createProducer(destination); try { postProcessProducer(producer, response); producer.send(response); } finally { JmsUtils.closeMessageProducer(producer); } }