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

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

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

Message.setJMSType介绍

[英]Sets the message type.

Some JMS providers use a message repository that contains the definitions of messages sent by applications. The JMSType header field may reference a message's definition in the provider's repository.

The JMS API does not define a standard message definition repository, nor does it define a naming policy for the definitions it contains.

Some messaging systems require that a message type definition for each application message be created and that each message specify its type. In order to work with such JMS providers, JMS clients should assign a value to JMSType, whether the application makes use of it or not. This ensures that the field is properly set for those providers that require it.

To ensure portability, JMS clients should use symbolic values for JMSType that can be configured at installation time to the values defined in the current provider's message repository. If string literals are used, they may not be valid type names for some JMS providers.
[中]设置消息类型。
一些JMS提供程序使用包含应用程序发送的消息定义的消息存储库。JMSType头字段可以引用提供者存储库中的消息定义。
JMS API没有定义标准的消息定义存储库,也没有为其包含的定义定义定义命名策略。
一些消息传递系统要求为每个应用程序消息创建消息类型定义,并要求每个消息指定其类型。为了使用这些JMS提供者,JMS客户机应该为JMSType分配一个值,无论应用程序是否使用它。这样可以确保为需要该字段的提供者正确设置该字段。
为了确保可移植性,JMS客户端应该为JMSType使用符号值,这些符号值可以在安装时配置为当前提供者的消息存储库中定义的值。如果使用字符串文字,则它们可能不是某些JMS提供程序的有效类型名。

代码示例

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

if (jmsType != null) {
  try {
    jmsMessage.setJMSType(jmsType);

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

message.setJMSCorrelationID(entry.getValue());
} else if (entry.getKey().equals(JmsHeaders.TYPE)) {
  message.setJMSType(entry.getValue());
} else if (entry.getKey().equals(JmsHeaders.REPLY_TO)) {
  Destination destination = buildDestination(entry.getValue());

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

@Test
public void jmsTypeMappedToHeader() throws JMSException {
  String type = "testing";
  javax.jms.Message jmsMessage = new StubTextMessage();
  jmsMessage.setJMSType(type);
  assertInboundHeader(jmsMessage, JmsHeaders.TYPE, type);
}

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

message.setJMSType(jmsHeaderType);

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

if (jmsType instanceof String) {
  try {
    jmsMessage.setJMSType((String) jmsType);

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

@Test
public void testJmsTypeMappedToHeader() throws JMSException {
  String type = "testing";
  javax.jms.Message jmsMessage = new StubTextMessage();
  jmsMessage.setJMSType(type);
  DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
  Map<String, Object> headers = mapper.toHeaders(jmsMessage);
  Object attrib = headers.get(JmsHeaders.TYPE);
  assertNotNull(attrib);
  assertSame(type, attrib);
}

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

public void setJMSType(String type) throws JMSException
{
 message.setJMSType(type);
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Override
public void setJMSType(final String type) throws JMSException {
  message.setJMSType(type);
}

代码示例来源:origin: org.jboss.genericjms/generic-jms-ra-jar

public void setJMSType(String type) throws JMSException {
  message.setJMSType(type);
}

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

/**
* Set type
* @param type The value
* @exception JMSException Thrown if an error occurs
*/
public void setJMSType(final String type) throws JMSException
{
 if (_log.isTraceEnabled())
 {
   _log.trace("setJMSType(" + type + ")");
 }
 _message.setJMSType(type);
}

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

private void setProperty(String property, Object value, Message message)
    throws JMSException
  {
    if(property == null)
      return;
    if(property.equals(JMSConstants.JMS_CORRELATION_ID))
      message.setJMSCorrelationID((String)value);
    else if(property.equals(JMSConstants.JMS_CORRELATION_ID_AS_BYTES))
      message.setJMSCorrelationIDAsBytes((byte[])value);
    else if(property.equals(JMSConstants.JMS_TYPE))
      message.setJMSType((String)value);
    else
      message.setObjectProperty(property, value);
  }
}

代码示例来源:origin: org.apache.axis/com.springsource.org.apache.axis

private void setProperty(String property, Object value, Message message)
    throws JMSException
  {
    if(property == null)
      return;
    if(property.equals(JMSConstants.JMS_CORRELATION_ID))
      message.setJMSCorrelationID((String)value);
    else if(property.equals(JMSConstants.JMS_CORRELATION_ID_AS_BYTES))
      message.setJMSCorrelationIDAsBytes((byte[])value);
    else if(property.equals(JMSConstants.JMS_TYPE))
      message.setJMSType((String)value);
    else
      message.setObjectProperty(property, value);
  }
}

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

/**
* Set type
*
* @param type The value
* @throws JMSException Thrown if an error occurs
*/
@Override
public void setJMSType(final String type) throws JMSException {
 if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
   ActiveMQRALogger.LOGGER.trace("setJMSType(" + type + ")");
 }
 message.setJMSType(type);
}

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

private void setProperty(String property, Object value, Message message)
    throws JMSException
  {
    if(property == null)
      return;
    if(property.equals(JMSConstants.JMS_CORRELATION_ID))
      message.setJMSCorrelationID((String)value);
    else if(property.equals(JMSConstants.JMS_CORRELATION_ID_AS_BYTES))
      message.setJMSCorrelationIDAsBytes((byte[])value);
    else if(property.equals(JMSConstants.JMS_TYPE))
      message.setJMSType((String)value);
    else
      message.setObjectProperty(property, value);
  }
}

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

/**
* Set type
*
* @param type The value
* @throws JMSException Thrown if an error occurs
*/
@Override
public void setJMSType(final String type) throws JMSException {
 if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
   ActiveMQRALogger.LOGGER.trace("setJMSType(" + type + ")");
 }
 message.setJMSType(type);
}

代码示例来源:origin: org.codehaus.stomp/stompconnect

protected void copyStandardHeadersFromFrameToMessage(StompFrame command, Message msg) throws JMSException, ProtocolException {
  final Map headers = new HashMap(command.getHeaders());
  // the standard JMS headers
  msg.setJMSCorrelationID((String) headers.remove(Stomp.Headers.Send.CORRELATION_ID));
  Object o = headers.remove(Stomp.Headers.Send.TYPE);
  if (o != null) {
    msg.setJMSType((String) o);
  }
  o = headers.remove(Stomp.Headers.Send.REPLY_TO);
  if (o != null) {
    msg.setJMSReplyTo(convertDestination((String) o));
  }
  // now the general headers
  for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
    Map.Entry entry = (Map.Entry) iter.next();
    String name = (String) entry.getKey();
    Object value = entry.getValue();
    msg.setObjectProperty(name, value);
  }
}

代码示例来源:origin: org.ballerinalang/ballerina-jms

@Override
  public void execute(Context context, CallableUnitCallback callableUnitCallback) {

    Struct messageStruct = BallerinaAdapter.getReceiverObject(context);
    Message message = BallerinaAdapter.getNativeObject(messageStruct,
                              Constants.JMS_MESSAGE_OBJECT,
                              Message.class,
                              context);
    String type = context.getStringArgument(0);

    try {
      message.setJMSType(type);
    } catch (JMSException e) {
      BallerinaAdapter.returnError("Error when setting float property", context, e);
    }
  }
}

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

@Test
public void testJMSType() throws Exception {
 Message m = queueProducerSession.createMessage();
 String originalType = "TYPE1";
 m.setJMSType(originalType);
 queueProducer.send(m);
 String gotType = queueConsumer.receive(1000).getJMSType();
 ProxyAssertSupport.assertEquals(originalType, gotType);
}

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

protected void prepareMessage(final Message m) throws JMSException {
 m.setBooleanProperty("booleanProperty", true);
 m.setByteProperty("byteProperty", (byte) 3);
 m.setDoubleProperty("doubleProperty", 4.0);
 m.setFloatProperty("floatProperty", 5.0f);
 m.setIntProperty("intProperty", 6);
 m.setLongProperty("longProperty", 7);
 m.setShortProperty("shortProperty", (short) 8);
 m.setStringProperty("stringProperty", "this is a String property");
 m.setJMSCorrelationID("this is the correlation ID");
 m.setJMSReplyTo(ActiveMQServerTestCase.topic1);
 m.setJMSType("someArbitraryType");
}

相关文章