如何列出 apache camel 中的所有 jms headers 属性?
How to list all the jms headers attributes in apache camel?
我正在尝试读取 apache-camel 路由中的 jms header。以下是我正在阅读 body & header 的路线。
String endPointTopic = "activemq:topic:geoLoc";
String endPointTopicOut = endPointTopic + "_outbox";
from(endPointTopic)
.log("Message from Topic is ${body} & header is ${header.Action}")
.to(endPointTopicOut);
基本上,从日志中我可以看到以下内容,这意味着我可以读取 body 但不能读取 header.
中的 ID
Message from Topic is GeoLocationInfoDTO{id=2, geoLocationUUId='null',
geoLocationName='null', geoLocationDesc='null',
geoLocationPolygon='null', geoLocationCenterLatitude='null',
geoLocationCenterLongitude='null'} & header is
下面是我通过 jms 模板将消息发布到 activeMQ 的代码。
private MessageHeaders getMessageHeaders(HttpMethod action) {
log.debug("DomainPublisher : getMessageHeaders");
Map <String, Object> headerMap = new HashMap<>();
headerMap.put("Action", action);
return new MessageHeaders(headerMap);
}
public void publish(BaseDTO dto, HttpMethod action) {
log.debug("DomainPublisher : type is : {} : ", dto.getClass().getName());
getJmsMessagingTemplate().convertAndSend(topicMap.get(dto.getClass().getName()), dto, getMessageHeaders(action));
}
注意:我还尝试记录 header id,例如 ${header.id} 而不是 ${header.Action} 但没有任何内容被打印出来。
而且我还想知道jms消息可用的所有header。
您可以记录与所有 headers 和属性的交换,如本例所示:
.to("log:like-to-see-all?level=INFO&showAll=true&multiline=true")
http://camel.apache.org/log.html
有关 JMS headers 的更多信息可在此处找到:http://camel.apache.org/jms.html
可能列表 headers:
- JMSCorrelationID - JMS 相关 ID。
- JMSDeliveryMode - JMS 传递模式。
- JMSDestination - JMS 目的地。
- JMSExpiration - JMS 到期。
- JMSMessageID - JMS 唯一消息 ID。
- JMSPriority - JMS 优先级(0 为最低优先级,9 为最高)。
- JMSRedelivered - 是否重新传送 JMS 消息。
- JMSReplyTo - JMS reply-to 目的地。
- JMSTimestamp - JMS 时间戳。
- JMSType - JMS 类型。
- JMSXGroupID - JMS 组 ID。
根据 Claus Ibsen 评论,JMS headers 只允许某些类型,如 headers,camel 将丢弃无效的 headers。看起来 HttpMethod(枚举类型)被 Camel 删除了。在我的代码中,我所要做的就是在构造 header.
时将 Enum 转换为 String
headerMap.put("Action", action);
to
headerMap.put("Action", action.toString());
可以通过 运行 以下命令从 karaf 客户端控制台查看 JMS headers:
activemq:browse --amqurl tcp://localhost:61616 --msgsel JMSMessaageID='1' -Vheader TEST.FOO
注意:以上均为示例值,请根据您的配置进行更改。
我正在尝试读取 apache-camel 路由中的 jms header。以下是我正在阅读 body & header 的路线。
String endPointTopic = "activemq:topic:geoLoc";
String endPointTopicOut = endPointTopic + "_outbox";
from(endPointTopic)
.log("Message from Topic is ${body} & header is ${header.Action}")
.to(endPointTopicOut);
基本上,从日志中我可以看到以下内容,这意味着我可以读取 body 但不能读取 header.
中的 IDMessage from Topic is GeoLocationInfoDTO{id=2, geoLocationUUId='null', geoLocationName='null', geoLocationDesc='null', geoLocationPolygon='null', geoLocationCenterLatitude='null', geoLocationCenterLongitude='null'} & header is
下面是我通过 jms 模板将消息发布到 activeMQ 的代码。
private MessageHeaders getMessageHeaders(HttpMethod action) {
log.debug("DomainPublisher : getMessageHeaders");
Map <String, Object> headerMap = new HashMap<>();
headerMap.put("Action", action);
return new MessageHeaders(headerMap);
}
public void publish(BaseDTO dto, HttpMethod action) {
log.debug("DomainPublisher : type is : {} : ", dto.getClass().getName());
getJmsMessagingTemplate().convertAndSend(topicMap.get(dto.getClass().getName()), dto, getMessageHeaders(action));
}
注意:我还尝试记录 header id,例如 ${header.id} 而不是 ${header.Action} 但没有任何内容被打印出来。
而且我还想知道jms消息可用的所有header。
您可以记录与所有 headers 和属性的交换,如本例所示:
.to("log:like-to-see-all?level=INFO&showAll=true&multiline=true")
http://camel.apache.org/log.html
有关 JMS headers 的更多信息可在此处找到:http://camel.apache.org/jms.html
可能列表 headers:
- JMSCorrelationID - JMS 相关 ID。
- JMSDeliveryMode - JMS 传递模式。
- JMSDestination - JMS 目的地。
- JMSExpiration - JMS 到期。
- JMSMessageID - JMS 唯一消息 ID。
- JMSPriority - JMS 优先级(0 为最低优先级,9 为最高)。
- JMSRedelivered - 是否重新传送 JMS 消息。
- JMSReplyTo - JMS reply-to 目的地。
- JMSTimestamp - JMS 时间戳。
- JMSType - JMS 类型。
- JMSXGroupID - JMS 组 ID。
根据 Claus Ibsen 评论,JMS headers 只允许某些类型,如 headers,camel 将丢弃无效的 headers。看起来 HttpMethod(枚举类型)被 Camel 删除了。在我的代码中,我所要做的就是在构造 header.
时将 Enum 转换为 StringheaderMap.put("Action", action);
to
headerMap.put("Action", action.toString());
可以通过 运行 以下命令从 karaf 客户端控制台查看 JMS headers:
activemq:browse --amqurl tcp://localhost:61616 --msgsel JMSMessaageID='1' -Vheader TEST.FOO
注意:以上均为示例值,请根据您的配置进行更改。