Example usage for javax.jms TextMessage setJMSDestination

List of usage examples for javax.jms TextMessage setJMSDestination

Introduction

In this page you can find the example usage for javax.jms TextMessage setJMSDestination.

Prototype


void setJMSDestination(Destination destination) throws JMSException;

Source Link

Document

Sets the Destination object for this message.

Usage

From source file:com.solveapuzzle.mapping.agnostic.JmsMessageListener.java

/**
 * Implementation of <code>MessageListener</code>.
 *//*from w  w w  .  j ava  2  s . c om*/
public void onMessage(Message message) {
    try {
        int messageCount = message.getIntProperty(JmsMessageProducer.MESSAGE_COUNT);

        logger.info("Processed message '{}'.  value={}", message, messageCount);

        counter.incrementAndGet();

        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            String msg = tm.getText();

            logger.info(" Read Transform property " + message.getStringProperty(TRANSFORM));

            try {

                String parser = tm.getStringProperty(PARSER);
                String key = tm.getStringProperty(TRANSFORM);

                logger.info(" Read Transform propertys " + parser + " " + key);

                String response = engine.onTransformEvent(this.createConfig(parser, key), tm.getText(),
                        Charset.defaultCharset());

                logger.info(" Response " + response);

                logger.info("message ReplyTo ID " + tm.getJMSCorrelationID());

                tm.setJMSDestination(this.outDestination);

                javax.jms.Queue queue = (javax.jms.Queue) tm.getJMSDestination();
                logger.info("ReplyTo Queue name = " + queue.getQueueName());

                tm.clearBody();

                tm.setText(response);
                // Push to response queue

            } catch (MappingException e) {
                logger.error("Mapping exception from transformation ", e);
                // push to mapping error Queue?
                // May be fixable with input xml change or due to data quality, invalid against schema

                throw new RuntimeException(e);
            } catch (ConfigurationException e) {
                logger.error("Configuration exception from transformation", e);
                // Can't fix - dead letter queue - but worth tracing what config went missing?
                throw new RuntimeException(e);
            }

        }
    } catch (JMSException e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}