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

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

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

Message.getJMSTimestamp介绍

[英]Gets the message timestamp.

The JMSTimestamp header field contains the time a message was handed off to a provider to be sent. It is not the time the message was actually transmitted, because the actual send may occur later due to transactions or other client-side queueing of messages.

When a message is sent, JMSTimestamp is ignored. When the send or publishmethod returns, it contains a time value somewhere in the interval between the call and the return. The value is in the format of a normal millis time value in the Java programming language.

Since timestamps take some effort to create and increase a message's size, some JMS providers may be able to optimize message overhead if they are given a hint that the timestamp is not used by an application. By calling the MessageProducer.setDisableMessageTimestamp method, a JMS client enables this potential optimization for all messages sent by that message producer. If the JMS provider accepts this hint, these messages must have the timestamp set to zero; if the provider ignores the hint, the timestamp must be set to its normal value.
[中]获取消息时间戳。
JMSTimestamp标头字段包含将消息传递给要发送的提供者的时间。这不是消息实际传输的时间,因为由于事务或其他客户端消息排队,实际发送可能会在稍后发生。
发送消息时,JMSTimestamp将被忽略。当send或publishmethod返回时,它在调用和返回之间的某个时间间隔中包含一个时间值。该值的格式为Java编程语言中的正常毫秒时间值。
由于时间戳需要一些努力来创建和增加消息的大小,因此如果一些JMS提供程序得到应用程序未使用时间戳的提示,它们可能能够优化消息开销。打电话给消息制作人。setDisableMessageTimestamp方法,JMS客户机为该消息生产者发送的所有消息启用此潜在优化。如果JMS提供程序接受此提示,则这些消息的时间戳必须设置为零;如果提供程序忽略该提示,则必须将时间戳设置为其正常值。

代码示例

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

sbuf.append(m.getJMSTimestamp());

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

headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());

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

private Map<String, String> extractMessageHeaders(final Message message) throws JMSException {
  final Map<String, String> messageHeaders = new HashMap<>();
  messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
  messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration()));
  messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority()));
  messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered()));
  messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
  messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID());
  messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID());
  messageHeaders.put(JmsHeaders.TYPE, message.getJMSType());
  String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO);
  if (replyToDestinationName != null) {
    messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName);
  }
  String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION);
  if (destinationName != null) {
    messageHeaders.put(JmsHeaders.DESTINATION, destinationName);
  }
  return messageHeaders;
}

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

attributes.put(ATTRIBUTE_PREFIX + JMS_PRIORITY, String.valueOf(message.getJMSPriority()));
attributes.put(ATTRIBUTE_PREFIX + JMS_REDELIVERED, String.valueOf(message.getJMSRedelivered()));
attributes.put(ATTRIBUTE_PREFIX + JMS_TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
return attributes;

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

protected ActiveMQMessage(final Message foreign, final byte type, final ClientSession session) throws JMSException {
 this(type, session);
 setJMSTimestamp(foreign.getJMSTimestamp());

代码示例来源: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-framework

@Test
public void jmsReadOnlyPropertiesNotMapped() throws JMSException {
  Message<String> message = initBuilder()
      .setHeader(JmsHeaders.DESTINATION, new Destination() {})
      .setHeader(JmsHeaders.DELIVERY_MODE, DeliveryMode.NON_PERSISTENT)
      .setHeader(JmsHeaders.EXPIRATION, 1000L)
      .setHeader(JmsHeaders.MESSAGE_ID, "abc-123")
      .setHeader(JmsHeaders.PRIORITY, 9)
      .setHeader(JmsHeaders.REDELIVERED, true)
      .setHeader(JmsHeaders.TIMESTAMP, System.currentTimeMillis())
      .build();
  javax.jms.Message jmsMessage = new StubTextMessage();
  mapper.fromHeaders(message.getHeaders(), jmsMessage);
  assertNull(jmsMessage.getJMSDestination());
  assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode());
  assertEquals(0, jmsMessage.getJMSExpiration());
  assertNull(jmsMessage.getJMSMessageID());
  assertEquals(javax.jms.Message.DEFAULT_PRIORITY, jmsMessage.getJMSPriority());
  assertFalse(jmsMessage.getJMSRedelivered());
  assertEquals(0, jmsMessage.getJMSTimestamp());
}

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

sbuf.append(m.getJMSTimestamp());

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

headers.put(JmsHeaders.TIMESTAMP, jmsMessage.getJMSTimestamp());

代码示例来源:origin: org.jboss.jbossas/jboss-as-connector

public long getJMSTimestamp() throws JMSException
{
 return message.getJMSTimestamp();
}

代码示例来源:origin: hazelcast/hazelcast-jet

private long handleJmsTimestamp(Message msg) {
  try {
    // as per `getJMSTimestamp` javadoc, it can return 0 if the timestamp was optimized away
    return msg.getJMSTimestamp() == 0 ? EventTimeMapper.NO_NATIVE_TIME : msg.getJMSTimestamp();
  } catch (JMSException e) {
    throw sneakyThrow(e);
  }
}

代码示例来源:origin: org.apache.qpid/qpid-jca

/**
* Get timestamp
* @return The value
* @exception JMSException Thrown if an error occurs
*/
public long getJMSTimestamp() throws JMSException
{
 if (_log.isTraceEnabled())
 {
   _log.trace("getJMSTimestamp()");
 }
 return _message.getJMSTimestamp();
}

代码示例来源:origin: org.apache.jmeter/ApacheJMeter_jms

public static StringBuilder requestHeaders(StringBuilder sb, Message msg){
  try {
    sb.append("JMSCorrelationId ").append(msg.getJMSCorrelationID()).append('\n');
    sb.append("JMSMessageId     ").append(msg.getJMSMessageID()).append('\n');
    sb.append("JMSTimestamp     ").append(msg.getJMSTimestamp()).append('\n');
    sb.append("JMSType          ").append(msg.getJMSType()).append('\n');
    sb.append("JMSExpiration    ").append(msg.getJMSExpiration()).append('\n');
    sb.append("JMSPriority      ").append(msg.getJMSPriority()).append('\n');
    sb.append("JMSDestination   ").append(msg.getJMSDestination()).append('\n');
  } catch (JMSException e) {
    sb.append("\nError: "+e.toString());
  }
  return sb;
}

代码示例来源:origin: org.seasar.jms/s2jms-core

public long getTimestamp() {
  if (message == null) {
    throw new EmptyRuntimeException("message");
  }
  try {
    return message.getJMSTimestamp();
  } catch (final JMSException e) {
    throw new SJMSRuntimeException("EJMS0001", new Object[] { e }, e);
  }
}

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

/**
* Get timestamp
*
* @return The value
* @throws JMSException Thrown if an error occurs
*/
@Override
public long getJMSTimestamp() throws JMSException {
 if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
   ActiveMQRALogger.LOGGER.trace("getJMSTimestamp()");
 }
 return message.getJMSTimestamp();
}

代码示例来源:origin: org.seasar.jms/s2jms-core

public long getTimestamp() {
  if (message == null) {
    throw new EmptyRuntimeException("message");
  }
  try {
    return message.getJMSTimestamp();
  } catch (final JMSException e) {
    throw new SJMSRuntimeException("EJMS0001", new Object[] { e }, e);
  }
}

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

/**
* Get timestamp
*
* @return The value
* @throws JMSException Thrown if an error occurs
*/
@Override
public long getJMSTimestamp() throws JMSException {
 if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
   ActiveMQRALogger.LOGGER.trace("getJMSTimestamp()");
 }
 return message.getJMSTimestamp();
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-jms

protected void addMessage(Message message) throws Exception {
 Instant currentMessageTimestamp = new Instant(message.getJMSTimestamp());
 state.atomicWrite(
   () -> {
    state.updateOldestPendingTimestampIf(currentMessageTimestamp, Instant::isBefore);
    state.addMessage(message);
   });
}

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

@Test
public void testJMSTimestamp() throws Exception {
 Message m = queueProducerSession.createMessage();
 long t1 = System.currentTimeMillis();
 queueProducer.send(m);
 long t2 = System.currentTimeMillis();
 long timestamp = queueConsumer.receive().getJMSTimestamp();
 ProxyAssertSupport.assertTrue(timestamp >= t1);
 ProxyAssertSupport.assertTrue(timestamp <= t2);
}

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

@Test
public void testDisabledTimestamp() throws Exception {
 Message m = queueProducerSession.createMessage();
 queueProducer.setDisableMessageTimestamp(true);
 queueProducer.send(m);
 ProxyAssertSupport.assertEquals(0L, queueConsumer.receive().getJMSTimestamp());
}

相关文章