Java Code Examples for org.springframework.jms.support.JmsUtils#closeMessageProducer()
The following examples show how to use
org.springframework.jms.support.JmsUtils#closeMessageProducer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAdaptableMessageListener.java From spring-analysis-note with MIT License | 6 votes |
/** * 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 * @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); } }
Example 2
Source File: JmsInvokerClientInterceptor.java From spring-analysis-note with MIT License | 6 votes |
/** * Actually execute the given request, sending the invoker request message * to the specified target queue and waiting for a corresponding response. * <p>The default implementation is based on standard JMS send/receive, * using a {@link javax.jms.TemporaryQueue} for receiving the response. * @param session the JMS Session to use * @param queue the resolved target Queue to send to * @param requestMessage the JMS Message to send * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure */ @Nullable protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException { TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { responseQueue = session.createTemporaryQueue(); producer = session.createProducer(queue); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); producer.send(requestMessage); long timeout = getReceiveTimeout(); return (timeout > 0 ? consumer.receive(timeout) : consumer.receive()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 3
Source File: JmsTemplate.java From spring-analysis-note with MIT License | 6 votes |
/** * Send the given JMS message. * @param session the JMS Session to operate on * @param destination the JMS Destination to send to * @param messageCreator callback to create a JMS Message * @throws JMSException if thrown by JMS API methods */ protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); MessageProducer producer = createProducer(session, destination); try { Message message = messageCreator.createMessage(session); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + message); } doSend(producer, message); // Check commit - avoid commit call within a JTA transaction. if (session.getTransacted() && isSessionLocallyTransacted(session)) { // Transacted session created by this template -> commit. JmsUtils.commitIfNecessary(session); } } finally { JmsUtils.closeMessageProducer(producer); } }
Example 4
Source File: AbstractAdaptableMessageListener.java From java-technology-stack with MIT License | 6 votes |
/** * 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 * @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); } }
Example 5
Source File: JmsInvokerClientInterceptor.java From java-technology-stack with MIT License | 6 votes |
/** * Actually execute the given request, sending the invoker request message * to the specified target queue and waiting for a corresponding response. * <p>The default implementation is based on standard JMS send/receive, * using a {@link javax.jms.TemporaryQueue} for receiving the response. * @param session the JMS Session to use * @param queue the resolved target Queue to send to * @param requestMessage the JMS Message to send * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure */ @Nullable protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException { TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { responseQueue = session.createTemporaryQueue(); producer = session.createProducer(queue); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); producer.send(requestMessage); long timeout = getReceiveTimeout(); return (timeout > 0 ? consumer.receive(timeout) : consumer.receive()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 6
Source File: JmsTemplate.java From java-technology-stack with MIT License | 6 votes |
/** * Send the given JMS message. * @param session the JMS Session to operate on * @param destination the JMS Destination to send to * @param messageCreator callback to create a JMS Message * @throws JMSException if thrown by JMS API methods */ protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); MessageProducer producer = createProducer(session, destination); try { Message message = messageCreator.createMessage(session); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + message); } doSend(producer, message); // Check commit - avoid commit call within a JTA transaction. if (session.getTransacted() && isSessionLocallyTransacted(session)) { // Transacted session created by this template -> commit. JmsUtils.commitIfNecessary(session); } } finally { JmsUtils.closeMessageProducer(producer); } }
Example 7
Source File: JmsInvokerClientInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Actually execute the given request, sending the invoker request message * to the specified target queue and waiting for a corresponding response. * <p>The default implementation is based on standard JMS send/receive, * using a {@link javax.jms.TemporaryQueue} for receiving the response. * @param session the JMS Session to use * @param queue the resolved target Queue to send to * @param requestMessage the JMS Message to send * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure */ protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException { TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { responseQueue = session.createTemporaryQueue(); producer = session.createProducer(queue); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); producer.send(requestMessage); long timeout = getReceiveTimeout(); return (timeout > 0 ? consumer.receive(timeout) : consumer.receive()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 8
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Send the given JMS message. * @param session the JMS Session to operate on * @param destination the JMS Destination to send to * @param messageCreator callback to create a JMS Message * @throws JMSException if thrown by JMS API methods */ protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); MessageProducer producer = createProducer(session, destination); try { Message message = messageCreator.createMessage(session); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + message); } doSend(producer, message); // Check commit - avoid commit call within a JTA transaction. if (session.getTransacted() && isSessionLocallyTransacted(session)) { // Transacted session created by this template -> commit. JmsUtils.commitIfNecessary(session); } } finally { JmsUtils.closeMessageProducer(producer); } }
Example 9
Source File: JmsInvokerServiceExporter.java From spring-analysis-note with MIT License | 5 votes |
/** * Send the given RemoteInvocationResult as a JMS message to the originator. * @param requestMessage current request message * @param session the JMS Session to use * @param result the RemoteInvocationResult object * @throws javax.jms.JMSException if thrown by trying to send the message */ protected void writeRemoteInvocationResult( Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException { Message response = createResponseMessage(requestMessage, session, result); MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo()); try { producer.send(response); } finally { JmsUtils.closeMessageProducer(producer); } }
Example 10
Source File: JmsTemplate.java From spring-analysis-note with MIT License | 5 votes |
/** * Send a request message to the given {@link Destination} and block until * a reply has been received on a temporary queue created on-the-fly. * <p>Return the response message or {@code null} if no message has * @throws JMSException if thrown by JMS API methods */ @Nullable protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { Message requestMessage = messageCreator.createMessage(session); responseQueue = session.createTemporaryQueue(); producer = session.createProducer(destination); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + requestMessage); } doSend(producer, requestMessage); return receiveFromConsumer(consumer, getReceiveTimeout()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 11
Source File: JmsInvokerServiceExporter.java From java-technology-stack with MIT License | 5 votes |
/** * Send the given RemoteInvocationResult as a JMS message to the originator. * @param requestMessage current request message * @param session the JMS Session to use * @param result the RemoteInvocationResult object * @throws javax.jms.JMSException if thrown by trying to send the message */ protected void writeRemoteInvocationResult( Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException { Message response = createResponseMessage(requestMessage, session, result); MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo()); try { producer.send(response); } finally { JmsUtils.closeMessageProducer(producer); } }
Example 12
Source File: JmsTemplate.java From java-technology-stack with MIT License | 5 votes |
/** * Send a request message to the given {@link Destination} and block until * a reply has been received on a temporary queue created on-the-fly. * <p>Return the response message or {@code null} if no message has * @throws JMSException if thrown by JMS API methods */ @Nullable protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { Message requestMessage = messageCreator.createMessage(session); responseQueue = session.createTemporaryQueue(); producer = session.createProducer(destination); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + requestMessage); } doSend(producer, requestMessage); return receiveFromConsumer(consumer, getReceiveTimeout()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 13
Source File: AbstractAdaptableMessageListener.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * 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 * @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); } }
Example 14
Source File: JmsInvokerServiceExporter.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Send the given RemoteInvocationResult as a JMS message to the originator. * @param requestMessage current request message * @param session the JMS Session to use * @param result the RemoteInvocationResult object * @throws javax.jms.JMSException if thrown by trying to send the message */ protected void writeRemoteInvocationResult( Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException { Message response = createResponseMessage(requestMessage, session, result); MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo()); try { producer.send(response); } finally { JmsUtils.closeMessageProducer(producer); } }
Example 15
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Send a request message to the given {@link Destination} and block until * a reply has been received on a temporary queue created on-the-fly. * <p>Return the response message or {@code null} if no message has * @throws JMSException if thrown by JMS API methods */ protected Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); TemporaryQueue responseQueue = null; MessageProducer producer = null; MessageConsumer consumer = null; try { Message requestMessage = messageCreator.createMessage(session); responseQueue = session.createTemporaryQueue(); producer = session.createProducer(destination); consumer = session.createConsumer(responseQueue); requestMessage.setJMSReplyTo(responseQueue); if (logger.isDebugEnabled()) { logger.debug("Sending created message: " + requestMessage); } doSend(producer, requestMessage); return doReceive(consumer, getReceiveTimeout()); } finally { JmsUtils.closeMessageConsumer(consumer); JmsUtils.closeMessageProducer(producer); if (responseQueue != null) { responseQueue.delete(); } } }
Example 16
Source File: MQTemplate.java From Thunder with Apache License 2.0 | 5 votes |
@Override protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { MessageProducer producer = null; try { Message message = messageCreator.createMessage(session); boolean async = message.getBooleanProperty(ThunderConstant.ASYNC_ATTRIBUTE_NAME); long timeout = message.getLongProperty(ThunderConstant.TIMEOUT_ATTRIBUTE_NAME); producer = createProducer(session, destination); // DeliveryMode.PERSISTENT:持久化模式,消息在硬盘堆积模式 // DeliveryMode.NON_PERSISTENT:非持久化模式,消息在内存堆积模式 if (async) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } producer.setTimeToLive(timeout); doSend(producer, message); if (session.getTransacted() && isSessionLocallyTransacted(session)) { JmsUtils.commitIfNecessary(session); } } finally { if (producer != null) { JmsUtils.closeMessageProducer(producer); } } }