javax.jms.Message.setJMSCorrelationID()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(235)

本文整理了Java中javax.jms.Message.setJMSCorrelationID()方法的一些代码示例,展示了Message.setJMSCorrelationID()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.setJMSCorrelationID()方法的具体详情如下:
包路径:javax.jms.Message
类名称:Message
方法名:setJMSCorrelationID

Message.setJMSCorrelationID介绍

[英]Sets the correlation ID for the message.

A client can use the JMSCorrelationID header field to link one message with another. A typical use is to link a response message with its request message.

JMSCorrelationID can hold one of the following:

  • A provider-specific message ID
  • An application-specific String
  • A provider-native byte[] value

Since each message sent by a JMS provider is assigned a message ID value, it is convenient to link messages via message ID. All message ID values must start with the 'ID:' prefix.

In some cases, an application (made up of several clients) needs to use an application-specific value for linking messages. For instance, an application may use JMSCorrelationID to hold a value referencing some external information. Application-specified values must not start with the 'ID:' prefix; this is reserved for provider-generated message ID values.

If a provider supports the native concept of correlation ID, a JMS client may need to assign specific JMSCorrelationID values to match those expected by clients that do not use the JMS API. A byte[] value is used for this purpose. JMS providers without native correlation ID values are not required to support byte[] values. The use of a byte[] value for JMSCorrelationID is non-portable.
[中]设置消息的相关ID。
客户端可以使用JMSCorrelationID头字段将一条消息链接到另一条消息。典型的用途是将响应消息与其请求消息链接起来。
JMSCorrelationID可以保存以下内容之一:
*提供程序特定的消息ID
*特定于应用程序的字符串
*提供程序本机字节[]值
由于JMS提供程序发送的每条消息都分配了一个消息ID值,因此通过消息ID链接消息非常方便。所有消息ID值都必须以“ID:”前缀开头。
在某些情况下,应用程序(由多个客户端组成)需要使用特定于应用程序的值来链接消息。例如,应用程序可以使用JMSCorrelationID来保存引用某些外部信息的值。应用程序指定的值不能以“ID:”前缀开头;这是为提供者生成的消息ID值保留的。
如果提供程序支持关联ID的本机概念,JMS客户机可能需要分配特定的JMSCorrelationID值,以匹配不使用JMS API的客户机所期望的值。字节[]值用于此目的。没有本机关联ID值的JMS提供程序不需要支持字节[]值。JMSCorrelationID使用byte[]值是不可移植的。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Post-process the given response message before it will be sent.
 * <p>The default implementation sets the response's correlation id
 * to the request message's correlation id, if any; otherwise to the
 * request message id.
 * @param request the original incoming JMS message
 * @param response the outgoing JMS message about to be sent
 * @throws JMSException if thrown by JMS API methods
 * @see javax.jms.Message#setJMSCorrelationID
 */
protected void postProcessResponse(Message request, Message response) throws JMSException {
  String correlation = request.getJMSCorrelationID();
  if (correlation == null) {
    correlation = request.getJMSMessageID();
  }
  response.setJMSCorrelationID(correlation);
}

代码示例来源:origin: wildfly/wildfly

message.setJMSCorrelationID(jmsHeaderCorrelationID);

代码示例来源:origin: spring-projects/spring-framework

jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create the invocation result response message.
 * <p>The default implementation creates a JMS ObjectMessage for the given
 * RemoteInvocationResult object. It sets the response's correlation id
 * to the request message's correlation id, if any; otherwise to the
 * request message id.
 * @param request the original request message
 * @param session the JMS session to use
 * @param result the invocation result
 * @return the message response to send
 * @throws javax.jms.JMSException if creating the message failed
 */
protected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result)
    throws JMSException {
  Message response = this.messageConverter.toMessage(result, session);
  String correlation = request.getJMSCorrelationID();
  if (correlation == null) {
    correlation = request.getJMSMessageID();
  }
  response.setJMSCorrelationID(correlation);
  return response;
}

代码示例来源:origin: apache/nifi

message.setJMSTimestamp(Long.parseLong(entry.getValue()));
} else if (entry.getKey().equals(JmsHeaders.CORRELATION_ID)) {
  message.setJMSCorrelationID(entry.getValue());
} else if (entry.getKey().equals(JmsHeaders.TYPE)) {
  message.setJMSType(entry.getValue());

代码示例来源:origin: spring-projects/spring-framework

@Test
public void jmsCorrelationIdMappedToHeader() throws JMSException {
  String correlationId = "ABC-123";
  javax.jms.Message jmsMessage = new StubTextMessage();
  jmsMessage.setJMSCorrelationID(correlationId);
  assertInboundHeader(jmsMessage, JmsHeaders.CORRELATION_ID, correlationId);
}

代码示例来源:origin: apache/activemq

/**
   * Copies the standard JMS and user defined properties from the givem
   * message to the specified message
   *
   * @param fromMessage the message to take the properties from
   * @param toMessage the message to add the properties to
   * @throws JMSException
   */
  public static void copyProperties(Message fromMessage, Message toMessage) throws JMSException {
    toMessage.setJMSMessageID(fromMessage.getJMSMessageID());
    toMessage.setJMSCorrelationID(fromMessage.getJMSCorrelationID());
    toMessage.setJMSReplyTo(transformDestination(fromMessage.getJMSReplyTo()));
    toMessage.setJMSDestination(transformDestination(fromMessage.getJMSDestination()));
    toMessage.setJMSDeliveryMode(fromMessage.getJMSDeliveryMode());
    toMessage.setJMSRedelivered(fromMessage.getJMSRedelivered());
    toMessage.setJMSType(fromMessage.getJMSType());
    toMessage.setJMSExpiration(fromMessage.getJMSExpiration());
    toMessage.setJMSPriority(fromMessage.getJMSPriority());
    toMessage.setJMSTimestamp(fromMessage.getJMSTimestamp());

    Enumeration propertyNames = fromMessage.getPropertyNames();

    while (propertyNames.hasMoreElements()) {
      String name = propertyNames.nextElement().toString();
      Object obj = fromMessage.getObjectProperty(name);
      toMessage.setObjectProperty(name, obj);
    }
  }
}

代码示例来源:origin: spring-projects/spring-integration

private void onMessageAsync(javax.jms.Message message, String correlationId) throws Exception {
  SettableListenableFuture<AbstractIntegrationMessageBuilder<?>> future = this.futures.remove(correlationId);
  if (future != null) {
    message.setJMSCorrelationID(null);
    future.set(buildReply(message));
  }
  else {
    logger.warn("Late reply for " + correlationId);
  }
}

代码示例来源:origin: spring-projects/spring-integration

private void copyCorrelationIdFromRequestToReply(javax.jms.Message requestMessage, javax.jms.Message replyMessage)
    throws JMSException {
  if (this.correlationKey != null) {
    if (this.correlationKey.equals("JMSCorrelationID")) {
      replyMessage.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
    }
    else {
      String value = requestMessage.getStringProperty(this.correlationKey);
      if (value != null) {
        replyMessage.setStringProperty(this.correlationKey, value);
      }
      else if (this.logger.isWarnEnabled()) {
        this.logger.warn("No property value available on request Message for correlationKey '"
            + this.correlationKey + "'");
      }
    }
  }
  else if (replyMessage.getJMSCorrelationID() == null) {
    replyMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());
  }
}

代码示例来源:origin: spring-projects/spring-integration

String correlation = UUID.randomUUID().toString().replaceAll("'", "''");
if (this.correlationKey.equals("JMSCorrelationID")) {
  jmsRequest.setJMSCorrelationID(correlation);
  messageSelector = "JMSCorrelationID = '" + correlation + "'";
  jmsRequest.setJMSCorrelationID(null);
  messageSelector = this.correlationKey + " = '" + correlation + "'";

代码示例来源:origin: spring-projects/spring-integration

correlation = this.gatewayCorrelation + "_" + Long.toString(this.correlationId.incrementAndGet());
if (this.correlationKey.equals("JMSCorrelationID")) {
  jmsRequest.setJMSCorrelationID(correlation);
  jmsRequest.setJMSCorrelationID(null);

代码示例来源:origin: spring-projects/spring-integration

jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);

代码示例来源:origin: spring-projects/spring-integration

jmsRequest.setJMSCorrelationID(null);
reply = doSendAndReceiveAsyncDefaultCorrelation(destination, jmsRequest, session, priority);
((javax.jms.Message) reply).setJMSCorrelationID(null);

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testJmsCorrelationIdMappedToHeader() throws JMSException {
  String correlationId = "ABC-123";
  javax.jms.Message jmsMessage = new StubTextMessage();
  jmsMessage.setJMSCorrelationID(correlationId);
  DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
  Map<String, Object> headers = mapper.toHeaders(jmsMessage);
  Object attrib = headers.get(JmsHeaders.CORRELATION_ID);
  assertNotNull(attrib);
  assertSame(correlationId, attrib);
}

代码示例来源:origin: spring-projects/spring-integration

final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> {
  jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
  return jmsReply;
});

代码示例来源:origin: spring-projects/spring-integration

final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), (MessageCreator) session -> {
  jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
  return jmsReply;
});

代码示例来源:origin: spring-projects/spring-integration

final javax.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> {
  jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
  return jmsReply;
});

代码示例来源:origin: stackoverflow.com

public void ConvertSend() {
Map map = new HashMap();
map.put("Name", "Vimal");
map.put("Age", new Integer(45));
jmsTemplate.convertAndSend("jmsQueue", map, new MessagePostProcessor() {
  public Message postProcessMessage(Message message) throws JMSException {
    message.setIntProperty("ID", 9999);
    message.setJMSCorrelationID("123-99999");
    return message;
    }
  });
}

代码示例来源:origin: techa03/goodsKill

@Override
  public Message createMessage(Session session) throws JMSException {
    Message mes = session.createMessage();
    mes.setJMSCorrelationID(message.getJMSCorrelationID());
    mes.setStringProperty("message", "dealSuccess!");
    return mes;
  }
});

代码示例来源:origin: apache/activemq-artemis

public void testJMSSelectors(ConnectionSupplier producerConnectionSupplier, ConnectionSupplier consumerConnectionSupplier) throws Exception {
 testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, NORMAL_QUEUE_NAME, message -> message.setStringProperty("color", "blue"), "color = 'blue'");
 testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, NORMAL_QUEUE_NAME, message -> message.setJMSCorrelationID("correlation"), "JMSCorrelationID = 'correlation'");
 testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, NORMAL_QUEUE_NAME, null, "JMSPriority = 1", Message.DEFAULT_DELIVERY_MODE, 1, Message.DEFAULT_TIME_TO_LIVE);
 testJMSSelector(producerConnectionSupplier, consumerConnectionSupplier, NORMAL_QUEUE_NAME, message -> message.setStringProperty("JMSXGroupID", "groupA"), "JMSXGroupID = 'groupA'");
}

相关文章