Example usage for org.springframework.jms.core JmsTemplate getReceiveTimeout

List of usage examples for org.springframework.jms.core JmsTemplate getReceiveTimeout

Introduction

In this page you can find the example usage for org.springframework.jms.core JmsTemplate getReceiveTimeout.

Prototype

public long getReceiveTimeout() 

Source Link

Document

Return the timeout to use for receive calls (in milliseconds).

Usage

From source file:org.apache.cxf.transport.jms.JMSConduit.java

/**
 * Send the JMS Request out and if not oneWay receive the response
 * //from   www .  j a v a 2  s . c  o  m
 * @param outMessage
 * @param request
 * @return inMessage
 */
public void sendExchange(final Exchange exchange, final Object request) {
    LOG.log(Level.FINE, "JMSConduit send message");

    final Message outMessage = exchange.getOutMessage();
    if (outMessage == null) {
        throw new RuntimeException("Exchange to be sent has no outMessage");
    }

    JMSMessageHeadersType headers = (JMSMessageHeadersType) outMessage
            .get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);

    JmsTemplate jmsTemplate = JMSFactory.createJmsTemplate(jmsConfig, headers);
    if (!exchange.isOneWay() && jmsListener == null) {
        jmsListener = JMSFactory.createJmsListener(jmsConfig, this, jmsConfig.getReplyDestination(), conduitId);
    }

    final javax.jms.Destination replyTo = exchange.isOneWay() ? null : jmsListener.getDestination();

    final String correlationId = (headers != null && headers.isSetJMSCorrelationID())
            ? headers.getJMSCorrelationID()
            : JMSUtils.createCorrelationId(jmsConfig.getConduitSelectorPrefix() + conduitId,
                    messageCount.incrementAndGet());

    MessageCreator messageCreator = new MessageCreator() {
        public javax.jms.Message createMessage(Session session) throws JMSException {
            String messageType = jmsConfig.getMessageType();
            final javax.jms.Message jmsMessage;
            jmsMessage = JMSUtils.buildJMSMessageFromCXFMessage(outMessage, request, messageType, session,
                    replyTo, correlationId);
            LOG.log(Level.FINE, "client sending request: ", jmsMessage);
            return jmsMessage;
        }
    };

    /**
     * If the message is not oneWay we will expect to receive a reply on the listener. To receive this
     * reply we add the correlationId and an empty CXF Message to the correlationMap. The listener will
     * fill to Message and notify this thread
     */
    if (!exchange.isOneWay()) {
        synchronized (exchange) {
            correlationMap.put(correlationId, exchange);
            jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);

            if (exchange.isSynchronous()) {
                try {
                    exchange.wait(jmsTemplate.getReceiveTimeout());
                } catch (InterruptedException e) {
                    correlationMap.remove(correlationId);
                    throw new RuntimeException(e);
                }
                correlationMap.remove(correlationId);
                if (exchange.get(CORRELATED) == null) {
                    throw new RuntimeException("Timeout receiving message with correlationId " + correlationId);
                }

            }
        }
    } else {
        jmsTemplate.send(jmsConfig.getTargetDestination(), messageCreator);
    }
}

From source file:org.springframework.batch.item.jms.JmsItemReader.java

/**
 * Setter for JMS template.//from   w w  w .  j av  a2  s.  c om
 * 
 * @param jmsTemplate a {@link JmsOperations} instance
 */
public void setJmsTemplate(JmsOperations jmsTemplate) {
    this.jmsTemplate = jmsTemplate;
    if (jmsTemplate instanceof JmsTemplate) {
        JmsTemplate template = (JmsTemplate) jmsTemplate;
        Assert.isTrue(template.getReceiveTimeout() != JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT,
                "JmsTemplate must have a receive timeout!");
        Assert.isTrue(template.getDefaultDestination() != null || template.getDefaultDestinationName() != null,
                "JmsTemplate must have a defaultDestination or defaultDestinationName!");
    }
}