Example usage for javax.jms Message setJMSCorrelationID

List of usage examples for javax.jms Message setJMSCorrelationID

Introduction

In this page you can find the example usage for javax.jms Message setJMSCorrelationID.

Prototype


void setJMSCorrelationID(String correlationID) throws JMSException;

Source Link

Document

Sets the correlation ID for the message.

Usage

From source file:nz.net.orcon.kanban.automation.CorrelationIdPostProcessor.java

@Override
public Message postProcessMessage(Message message) throws JMSException {
    message.setJMSCorrelationID(correlationId);
    return message;
}

From source file:com.adaptris.core.jms.MessageIdCorrelationIdSource.java

@Override
public void processCorrelationId(AdaptrisMessage src, Message dest) throws JMSException {
    dest.setJMSCorrelationID(src.getUniqueId());
}

From source file:org.fatal1t.forexapp.spring.api.adapters.SyncListener.java

private void sendMessage(String message, String CorelId, Destination queue)
        throws JmsException, BeansException {
    MessageCreator messageCreator = (javax.jms.Session session1) -> {
        Message nMessage = session1.createTextMessage(message);
        nMessage.setJMSCorrelationID(CorelId);

        return nMessage;
    };/*from www. j a  va  2s  .  c om*/

    JmsTemplate jmsTemplate = this.context.getBean(JmsTemplate.class);
    log.info("Target queue: " + queue.toString());
    log.info("Sending back: " + CorelId + " " + message.substring(0, 10));
    jmsTemplate.send(queue, messageCreator);
}

From source file:org.globus.crux.messaging.utils.JAXBMessageConverter.java

/**
 * <p>//from   w  w  w.j av  a2 s .c  o  m
 * Intended to be overwritten for each JMS Provider implementation (Websphere MQ, Tibco EMS, Active MQ ...).
 * </p>
 * <p>
 * If JMS provider supports messages encoding, this charset must be in sync with the encoding used to generate the XML text output
 * </p>
 */
protected void postProcessResponseMessage(Message textMessage) throws JMSException {
    textMessage.setJMSCorrelationID(this.resourceId);
}

From source file:com.fusesource.forge.jmstest.tests.AsyncConsumer.java

public void onMessage(Message msg) {
    if (receiveCount != null) {
        receiveCount.incrementAndGet();/*from w w  w .  ja v a  2 s.c  o  m*/
    }
    MessageProducer producer = null;
    try {
        Destination replyDest = msg.getJMSReplyTo();
        if (replyDest != null) {
            Message response = getSession().createTextMessage("Response");
            response.setStringProperty("ServedBy", getName());
            response.setJMSCorrelationID(msg.getJMSCorrelationID());
            for (Enumeration<?> en = msg.getPropertyNames(); en.hasMoreElements();) {
                String key = (String) en.nextElement();
                Object value = msg.getObjectProperty(key);
                if (key.equals("BrokerStamp")) {
                    value = value.toString() + " --";
                }
                response.setObjectProperty(key, value);
            }
            producer = getSession().createProducer(replyDest);
            producer.send(response);
        }
    } catch (Exception e) {
        LOG.error(e);
    } finally {
        if (producer != null) {
            try {
                producer.close();
            } catch (Exception e) {
            }
        }
    }
}

From source file:com.adaptris.core.jms.activemq.BlobMessageTranslatorTest.java

public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    EmbeddedActiveMq activeMqBroker = new EmbeddedActiveMq();
    JmsConnection conn = null;//from   w ww .  j a  v a 2s .  c o m
    try {
        activeMqBroker.start();
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);

        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);

        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);

        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
        activeMqBroker.destroy();
    }

}

From source file:org.nebulaframework.grid.cluster.manager.services.jobs.splitaggregate.SplitterServiceImpl.java

/**
 * Enqueues a given Task with in the {@code TaskQueue}.
 * /*from  w w  w. j a  v a 2 s  .  co m*/
 * @param jobId String JobId
 * @param taskId int TaskId (Sequence Number of Task)
 * @param task {@code GridTask} task
 */
private void enqueueTask(final GridJobProfile profile, final int taskId, GridTask<?> task) {

    final String jobId = profile.getJobId();

    // Send GridTask as a JMS Object Message to TaskQueue
    jmsTemplate.convertAndSend(JMSNamingSupport.getTaskQueueName(jobId), task, new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            // Post Process to include Meta Data
            message.setJMSCorrelationID(jobId); // Set Correlation ID to Job Id
            message.setIntProperty("taskId", taskId); // Put taskId as a property
            log.debug("Enqueued Task : " + taskId);
            return message;
        }
    });

    profile.getTaskTracker().taskEnqueued(taskId);
}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.jms.client.OrderTrackingJmsProducerImpl.java

@Override
public String sendMessage(final String activitySummaryMessage) throws OrderTrackingException {
    LOGGER.info("========  sending messge to the JmsQueue Starts===========");
    String deliveryStatus = "";
    final String correlationId = UUID.randomUUID().toString();
    try {/*from www  . j  ava  2 s  .co  m*/
        getJmsTemplate().send(new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                MessageConverter messageConverter = jmsTemplate.getMessageConverter();
                Message jmsMessage = messageConverter.toMessage(activitySummaryMessage, session);
                jmsMessage.setStringProperty(properties.getHqLvqName(), activitySummaryMessage);
                jmsMessage.setJMSCorrelationID(correlationId);
                return jmsMessage;
            }
        });

        LOGGER.info("========  sending messge to the JmsQueue Ends===========");
        deliveryStatus = OrderTrackingConstants.MSG_STATUS_SUCCESS;

    } catch (Exception ex) {

        LOGGER.info("====Error occured on sending the message to QUEUE==== " + ex);
        deliveryStatus = OrderTrackingConstants.MSG_STATUS_FAILED;
        throw new OrderTrackingException(OrderTrackingExceptionInfo.FOT006,
                "Error occured while  creating a queue or sending message to the queue.");

    }
    return deliveryStatus;

}

From source file:com.adaptris.core.jms.MetadataCorrelationIdSource.java

/**
 * <p>//from  w  w w.j  a va  2 s  .c om
 * If no metadata key is configured or if no value is stored against the
 * configured key a message is logged to this effect and no Exception is
 * thrown.
 * </p>
 *
 * @see com.adaptris.core.jms.CorrelationIdSource#processCorrelationId
 *      (com.adaptris.core.AdaptrisMessage, javax.jms.Message)
 */
public void processCorrelationId(AdaptrisMessage src, Message dest) throws JMSException {
    String correlationId = src.getMetadataValue(getMetadataKey());
    if (isEmpty(correlationId)) {
        log.warn("no value for metadata key [{}]", getMetadataKey());
    } else {
        dest.setJMSCorrelationID(correlationId);
        log.debug("set correlation ID to [{}]", correlationId);
    }
}

From source file:org.logicblaze.lingo.jms.JmsServiceExporterMessageListener.java

/**
 * Creates the invocation result response message
 * //from w  w  w. j  a  v  a  2  s . c  o m
 * @param session
 *            the JMS session to use
 * @param message
 *            the original request message, in case we want to attach any
 *            properties etc.
 * @param result
 *            the invocation result
 * @return the message response to send
 * @throws javax.jms.JMSException
 *             if creating the messsage failed
 */
protected Message createResponseMessage(Session session, Message message, RemoteInvocationResult result)
        throws JMSException {
    // an alternative strategy could be to use XStream and text messages
    // though some JMS providers, like ActiveMQ, might do this kind of thing
    // for us under the covers
    if (result == null) {
        throw new IllegalArgumentException("result cannot be null");
    }

    Message answer = getMarshaller().createResponseMessage(session, result, message);

    // lets preserve the correlation ID
    answer.setJMSCorrelationID(message.getJMSCorrelationID());
    return answer;
}