当前位置: 首页>>代码示例>>Java>>正文


Java TextMessage.setJMSCorrelationID方法代码示例

本文整理汇总了Java中javax.jms.TextMessage.setJMSCorrelationID方法的典型用法代码示例。如果您正苦于以下问题:Java TextMessage.setJMSCorrelationID方法的具体用法?Java TextMessage.setJMSCorrelationID怎么用?Java TextMessage.setJMSCorrelationID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.TextMessage的用法示例。


在下文中一共展示了TextMessage.setJMSCorrelationID方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receiveAndRespondWithMessageIdAsCorrelationId

import javax.jms.TextMessage; //导入方法依赖的package包/类
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
    final javax.jms.Message inMessage = consumer.receive();

    String requestMessageId = inMessage.getJMSMessageID();
    LOG.debug("Received message " + requestMessageId);
    final TextMessage replyMessage = session.createTextMessage("Result");
    replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
    final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
    LOG.debug("Sending reply to " + inMessage.getJMSReplyTo());
    producer.send(replyMessage);

    producer.close();
    consumer.close();
    session.close();
    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:PooledConnectionTempQueueTest.java

示例2: handleMessage

import javax.jms.TextMessage; //导入方法依赖的package包/类
private void handleMessage(MessageHandler handler, Message message, Session session) {
    if (! (message instanceof TextMessage)) {
        return;
    }
    TextMessage textMessage = (TextMessage) message;
    String text = null;
    String requestId = UUID.randomUUID().toString();
    try {
        text = textMessage.getText();
        if (StringUtils.isNotEmpty(message.getJMSCorrelationID())) {
            requestId = message.getJMSCorrelationID();
        }

        MDC.put(X_OBOS_REQUEST_ID, requestId);

        log.info("Received message '{}'", text);

        handler.handle(new ObjectMapper().readTree(text));
    } catch (Exception e) {
        log.error("Failed to process message", e);
        try {
            TextMessage errorMessage = session.createTextMessage(text);
            errorMessage.setJMSCorrelationID(requestId);

            Queue queue = session.createQueue(queueError);
            MessageProducer errorProducer = session.createProducer(queue);
            errorProducer.send(errorMessage);
        } catch (JMSException jmse) {
            log.error("Failed to create error message", jmse);
        }
    } finally {
        MDC.remove(X_OBOS_REQUEST_ID);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:35,代码来源:ActiveMqListener.java

示例3: wrapAndSendResponseInternal

import javax.jms.TextMessage; //导入方法依赖的package包/类
private void wrapAndSendResponseInternal(Message incoming, List<B> response) throws JMSException {
    String text;
    try {
        text = JsonMapper.serialize(response);
    } catch (JsonProcessingException e) {
        getLogger().warn("Failed to convert response to text. Will not send response");
        return;
    }

    getLogger().debug("Response (object): {}", response);
    getLogger().debug("Response (string): {}", text);

    TextMessage msg = getContext().createTextMessage(text);
    msg.setJMSCorrelationID(incoming.getJMSCorrelationID());

    getContext().createProducer()
                .setDisableMessageID(true)
                .setDisableMessageTimestamp(true)
                .setDeliveryMode(DeliveryMode.NON_PERSISTENT)
                .send(incoming.getJMSReplyTo(), msg);
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:22,代码来源:AbstractSharingListener.java

示例4: publishMessage

import javax.jms.TextMessage; //导入方法依赖的package包/类
/**
 * Publish message.
 *
 * @param waitTaskName the wait task name
 * @param woType       the wo type
 * @throws JMSException the jMS exception
 */
public void publishMessage(String processId, String execId, CmsWorkOrderSimpleBase wo, String waitTaskName, String woType) throws JMSException {
    SimpleDateFormat format = new SimpleDateFormat(CmsConstants.SEARCH_TS_PATTERN);
    wo.getSearchTags().put(CmsConstants.REQUEST_ENQUE_TS, format.format(new Date()));
    //guarantee non empty-value for searchMap
    if (version != null && StringUtils.isNotBlank(version.getGitVersion())) {
        wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, version.getGitVersion());
    } else {
        wo.getSearchTags().put(CONTROLLLER_VERSION_SEARCH_TAG, DEFAULT_VERSION);
    }
    TextMessage message = session.createTextMessage(gson.toJson(wo));
    String corelationId = processId + "!" + execId + "!" + waitTaskName+"!"+getCtxtId(wo);
    message.setJMSCorrelationID(corelationId);
    message.setStringProperty("task_id", corelationId);
    message.setStringProperty("type", woType);
    String queueName;
    if ("true".equals(System.getProperty(USE_SHARED_FLAG))) {
        queueName = SHARED_QUEUE;
    } else {
        queueName = (wo.getCloud().getCiAttributes().get("location").replaceAll("/", ".") + QUEUE_SUFFIX).substring(
                1);
    }
    bindingQueusMap.computeIfAbsent(queueName, k -> {
        try {
            return newMessageProducer(k);
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }
    }).send(message);
    
    if (logger.isDebugEnabled()) {
        logger.debug("Published: " + message.getText());
    }

    logger.info("Posted message with id "+ corelationId +" to q: "+queueName);

}
 
开发者ID:oneops,项目名称:oneops,代码行数:44,代码来源:InductorPublisher.java

示例5: queueMessage

import javax.jms.TextMessage; //导入方法依赖的package包/类
static void queueMessage(Session session, String text, String queueName) {
    try {
        Queue queue = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(queue);

        TextMessage message = session.createTextMessage(text);
        message.setJMSCorrelationID(MDC.get(X_OBOS_REQUEST_ID));

        producer.send(message);
        session.commit();
    } catch (JMSException ex) {
        throw new MessageQueueException("Could not queue message '" + text + "'", ex);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:15,代码来源:ActiveMqUtils.java

示例6: requeueFailedMessages

import javax.jms.TextMessage; //导入方法依赖的package包/类
@Override
public void requeueFailedMessages() {
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = ActiveMqUtils.startSession(connection);

        int count = getQueueSize(session, queueError);

        if (count < 1) {
            return;
        }

        log.info("Requeuing {} failed messages...", count);

        Queue queueErr = session.createQueue(queueError);
        MessageConsumer consumer = session.createConsumer(queueErr);

        Queue queueRetry = session.createQueue(queueInput);
        MessageProducer producer = session.createProducer(queueRetry);

        for (int consumed = 0; consumed < count; consumed++) {
            TextMessage message = (TextMessage) consumer.receive(REQUEUE_TIMEOUT);

            if (message == null) {
                continue;
            }

            String text = message.getText();
            String requestId = message.getJMSCorrelationID();

            log.info("Requeuing message '{}'", text);

            try {
                TextMessage newMessage = session.createTextMessage(text);
                newMessage.setJMSCorrelationID(requestId);

                producer.send(newMessage);
            } catch (Exception e) {
                log.error("Failed to requeue message", e);
            }

            message.acknowledge();
            session.commit();
        }

        producer.close();
        consumer.close();
    } catch (JMSException ex) {
        throw new MessageQueueException("Failed to requeue failed messages", ex);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:52,代码来源:ActiveMqListener.java

示例7: testConsumerWithBasicRecover

import javax.jms.TextMessage; //导入方法依赖的package包/类
@Parameters({ "broker-port", "admin-username", "admin-password", "broker-hostname" })
@Test
public void testConsumerWithBasicRecover(String port,
                                        String adminUsername,
                                        String adminPassword,
                                        String brokerHostname) throws Exception {
    String queueName = "testConsumerWithBasicRecover";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish message
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

    TextMessage firstMessage = producerSession.createTextMessage("First message for reject test");
    TextMessage secondMessage = producerSession.createTextMessage("Second message for reject test");
    String correlationIdOne = "1";
    String correlationIdTwo = "2";
    firstMessage.setJMSCorrelationID(correlationIdOne);
    secondMessage.setJMSCorrelationID(correlationIdTwo);
    producer.send(firstMessage);
    producer.send(secondMessage);
    producerSession.close();

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    Message message = consumer.receive(5000);
    Assert.assertNotNull(message, "Message was not received");

    subscriberSession.recover();

    // Message order can change after recovering
    for (int i = 0; i < 2; i++) {
        message = consumer.receive(5000);
        Assert.assertNotNull(message, "Requeued message was not received");

        if (correlationIdOne.equals(message.getJMSCorrelationID())) {
            Assert.assertTrue(message.getJMSRedelivered(), "Redelivered flag was set in second message" + message);
        } else {
            Assert.assertFalse(message.getJMSRedelivered(), "Redelivered flag was set in first message");
        }

        message.acknowledge();
    }

    connection.close();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:59,代码来源:QueueConsumerTest.java


注:本文中的javax.jms.TextMessage.setJMSCorrelationID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。