org.springframework.jms.support.JmsUtils Java Examples
The following examples show how to use
org.springframework.jms.support.JmsUtils.
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: JmsInvokerClientInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #2
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 #3
Source File: JmsInvokerClientInterceptor.java From java-technology-stack with MIT License | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #4
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public <T> T execute(final Destination destination, final ProducerCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(new SessionCallback<T>() { @Override public T doInJms(Session session) throws JMSException { MessageProducer producer = createProducer(session, destination); try { return action.doInJms(session, producer); } finally { JmsUtils.closeMessageProducer(producer); } } }, false); }
Example #5
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 #6
Source File: SimpleMessageListenerContainer.java From java-technology-stack with MIT License | 6 votes |
/** * Destroy the registered JMS Sessions and associated MessageConsumers. */ @Override protected void doShutdown() throws JMSException { synchronized (this.consumersMonitor) { if (this.consumers != null) { logger.debug("Closing JMS MessageConsumers"); for (MessageConsumer consumer : this.consumers) { JmsUtils.closeMessageConsumer(consumer); } if (this.sessions != null) { logger.debug("Closing JMS Sessions"); for (Session session : this.sessions) { JmsUtils.closeSession(session); } } } } }
Example #7
Source File: DefaultMessageListenerContainer.java From java-technology-stack with MIT License | 6 votes |
private void clearResources() { if (sharedConnectionEnabled()) { synchronized (sharedConnectionMonitor) { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } } else { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } if (this.consumer != null) { synchronized (lifecycleMonitor) { registeredWithDestination--; } } this.consumer = null; this.session = null; }
Example #8
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public <T> T execute(final String destinationName, final ProducerCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(new SessionCallback<T>() { @Override public T doInJms(Session session) throws JMSException { Destination destination = resolveDestinationName(session, destinationName); MessageProducer producer = createProducer(session, destination); try { return action.doInJms(session, producer); } finally { JmsUtils.closeMessageProducer(producer); } } }, false); }
Example #9
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 #10
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 #11
Source File: JmsTemplate.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public <T> T browseSelected(final String queueName, @Nullable final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { Queue queue = (Queue) getDestinationResolver().resolveDestinationName(session, queueName, false); QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } }, true); }
Example #12
Source File: JmsTemplate.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public <T> T browseSelected(final Queue queue, @Nullable final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } }, true); }
Example #13
Source File: JmsTemplate.java From spring-analysis-note with MIT License | 6 votes |
/** * A variant of {@link #execute(SessionCallback, boolean)} that explicitly * creates a non-transactional {@link Session}. The given {@link SessionCallback} * does not participate in an existing transaction. */ @Nullable private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection con = null; Session session = null; try { con = createConnection(); session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); if (startConnection) { con.start(); } if (logger.isDebugEnabled()) { logger.debug("Executing callback on JMS Session: " + session); } return action.doInJms(session); } catch (JMSException ex) { throw convertJmsAccessException(ex); } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), startConnection); } }
Example #14
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 #15
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 #16
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * A variant of {@link #execute(SessionCallback, boolean)} that explicitly * creates a non-transactional {@link Session}. The given {@link SessionCallback} * does not participate in an existing transaction. */ private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection con = null; Session session = null; try { con = getConnectionFactory().createConnection(); session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); if (startConnection) { con.start(); } if (logger.isDebugEnabled()) { logger.debug("Executing callback on JMS Session: " + session); } return action.doInJms(session); } catch (JMSException ex) { throw convertJmsAccessException(ex); } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), startConnection); } }
Example #17
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public <T> T browseSelected(final Queue queue, final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(new SessionCallback<T>() { @Override public T doInJms(Session session) throws JMSException { QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } } }, true); }
Example #18
Source File: JmsTemplate.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public <T> T browseSelected(final String queueName, final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(new SessionCallback<T>() { @Override public T doInJms(Session session) throws JMSException { Queue queue = (Queue) getDestinationResolver().resolveDestinationName(session, queueName, false); QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } } }, true); }
Example #19
Source File: JmsTemplate.java From java-technology-stack with MIT License | 6 votes |
/** * A variant of {@link #execute(SessionCallback, boolean)} that explicitly * creates a non-transactional {@link Session}. The given {@link SessionCallback} * does not participate in an existing transaction. */ @Nullable private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection con = null; Session session = null; try { con = createConnection(); session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); if (startConnection) { con.start(); } if (logger.isDebugEnabled()) { logger.debug("Executing callback on JMS Session: " + session); } return action.doInJms(session); } catch (JMSException ex) { throw convertJmsAccessException(ex); } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), startConnection); } }
Example #20
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 #21
Source File: JmsInvokerClientInterceptor.java From spring-analysis-note with MIT License | 6 votes |
/** * Execute the given remote invocation, sending an invoker request message * to this accessor's target queue and waiting for a corresponding response. * @param invocation the RemoteInvocation to execute * @return the RemoteInvocationResult object * @throws JMSException in case of JMS failure * @see #doExecuteRequest */ protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException { Connection con = createConnection(); Session session = null; try { session = createSession(con); Queue queueToUse = resolveQueue(session); Message requestMessage = createRequestMessage(session, invocation); con.start(); Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage); if (responseMessage != null) { return extractInvocationResult(responseMessage); } else { return onReceiveTimeout(invocation); } } finally { JmsUtils.closeSession(session); ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true); } }
Example #22
Source File: JmsTemplate.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable public <T> T browseSelected(final Queue queue, @Nullable final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } }, true); }
Example #23
Source File: JmsTemplate.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable public <T> T browseSelected(final String queueName, @Nullable final String messageSelector, final BrowserCallback<T> action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { Queue queue = (Queue) getDestinationResolver().resolveDestinationName(session, queueName, false); QueueBrowser browser = createBrowser(session, queue, messageSelector); try { return action.doInJms(session, browser); } finally { JmsUtils.closeQueueBrowser(browser); } }, true); }
Example #24
Source File: SimpleMessageListenerContainer.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Destroy the registered JMS Sessions and associated MessageConsumers. */ @Override protected void doShutdown() throws JMSException { synchronized (this.consumersMonitor) { if (this.consumers != null) { logger.debug("Closing JMS MessageConsumers"); for (MessageConsumer consumer : this.consumers) { JmsUtils.closeMessageConsumer(consumer); } logger.debug("Closing JMS Sessions"); for (Session session : this.sessions) { JmsUtils.closeSession(session); } } } }
Example #25
Source File: DefaultMessageListenerContainer.java From spring4-understanding with Apache License 2.0 | 6 votes |
private void clearResources() { if (sharedConnectionEnabled()) { synchronized (sharedConnectionMonitor) { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } } else { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } if (this.consumer != null) { synchronized (lifecycleMonitor) { registeredWithDestination--; } } this.consumer = null; this.session = null; }
Example #26
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 #27
Source File: SimpleMessageListenerContainer.java From spring-analysis-note with MIT License | 6 votes |
/** * Destroy the registered JMS Sessions and associated MessageConsumers. */ @Override protected void doShutdown() throws JMSException { synchronized (this.consumersMonitor) { if (this.consumers != null) { logger.debug("Closing JMS MessageConsumers"); for (MessageConsumer consumer : this.consumers) { JmsUtils.closeMessageConsumer(consumer); } if (this.sessions != null) { logger.debug("Closing JMS Sessions"); for (Session session : this.sessions) { JmsUtils.closeSession(session); } } } } }
Example #28
Source File: DefaultMessageListenerContainer.java From spring-analysis-note with MIT License | 6 votes |
private void clearResources() { if (sharedConnectionEnabled()) { synchronized (sharedConnectionMonitor) { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } } else { JmsUtils.closeMessageConsumer(this.consumer); JmsUtils.closeSession(this.session); } if (this.consumer != null) { synchronized (lifecycleMonitor) { registeredWithDestination--; } } this.consumer = null; this.session = null; }
Example #29
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 #30
Source File: DefaultMessageListenerContainer.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Handle the given exception that arose during setup of a listener. * Called for every such exception in every concurrent listener. * <p>The default implementation logs the exception at warn level * if not recovered yet, and at debug level if already recovered. * Can be overridden in subclasses. * @param ex the exception to handle * @param alreadyRecovered whether a previously executing listener * already recovered from the present listener setup failure * (this usually indicates a follow-up failure than can be ignored * other than for debug log purposes) * @see #recoverAfterListenerSetupFailure() */ protected void handleListenerSetupFailure(Throwable ex, boolean alreadyRecovered) { if (ex instanceof JMSException) { invokeExceptionListener((JMSException) ex); } if (ex instanceof SharedConnectionNotInitializedException) { if (!alreadyRecovered) { logger.info("JMS message listener invoker needs to establish shared Connection"); } } else { // Recovery during active operation.. if (alreadyRecovered) { logger.debug("Setup of JMS message listener invoker failed - already recovered by other invoker", ex); } else { StringBuilder msg = new StringBuilder(); msg.append("Setup of JMS message listener invoker failed for destination '"); msg.append(getDestinationDescription()).append("' - trying to recover. Cause: "); msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage()); if (logger.isDebugEnabled()) { logger.warn(msg, ex); } else { logger.warn(msg); } } } }