Spring 启动 JMS MappingJackson2MessageConverter 找不到 `_type` 字段,即使它存在
Spring Boot JMS MappingJackson2MessageConverter cannot find `_type` field even though it exists
我正在使用 Spring 启动来接收 JMS 消息并使用 cURL 来发送它。
这是 Spring 配置:
@Bean
public MessageConverter jsonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
当我尝试发送消息时,我得到:
org.springframework.jms.support.converter.MessageConversionException: Could not find type id property [_type] on message [ID:b5151b422e8a-41371-1526292561432-6:3:1:1:14] from destination [queue://ssg]
我的 cURL 命令是:
curl -u 'un:pw' -H '_type: com.me.SSMessage' -d 'body={"_type": "com.me.SSMessage", "url": "https://www.google.com"}' "http://localhost:8161/api/message/ssg?type=queue&clientId=consumerA"
_type
被设置为 header(我认为这是不对的)和 JSON 中的字段。为什么我会从 Spring 应用程序中收到该错误消息?
这比 Spring 更像是一个 Activemq/REST 问题:
converter.setTypeIdPropertyName("_type");
这设置了一个 JMS 消息 属性,它不是消息中的一个字段。关于消息头的东西在这里:https://docs.oracle.com/javaee/7/api/javax/jms/Message.html
诀窍是如何使用 Activemq REST 接口(以及 CURL)来做到这一点。答案是将其作为 GET
参数添加到查询中:
curl -u 'un:pw' -H '_type: com.me.SSMessage' \
-d 'body={"url": "https://www.google.com"}' \
"http://localhost:8161/api/message/ssg? \
type=queue&clientId=consumerA&_type=com.me.SSMessage"
编辑:我无法测试,但我认为上面不需要 -H '_type: com.me.SSMessage'
...
我正在使用 Spring 启动来接收 JMS 消息并使用 cURL 来发送它。
这是 Spring 配置:
@Bean
public MessageConverter jsonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
当我尝试发送消息时,我得到:
org.springframework.jms.support.converter.MessageConversionException: Could not find type id property [_type] on message [ID:b5151b422e8a-41371-1526292561432-6:3:1:1:14] from destination [queue://ssg]
我的 cURL 命令是:
curl -u 'un:pw' -H '_type: com.me.SSMessage' -d 'body={"_type": "com.me.SSMessage", "url": "https://www.google.com"}' "http://localhost:8161/api/message/ssg?type=queue&clientId=consumerA"
_type
被设置为 header(我认为这是不对的)和 JSON 中的字段。为什么我会从 Spring 应用程序中收到该错误消息?
这比 Spring 更像是一个 Activemq/REST 问题:
converter.setTypeIdPropertyName("_type");
这设置了一个 JMS 消息 属性,它不是消息中的一个字段。关于消息头的东西在这里:https://docs.oracle.com/javaee/7/api/javax/jms/Message.html
诀窍是如何使用 Activemq REST 接口(以及 CURL)来做到这一点。答案是将其作为 GET
参数添加到查询中:
curl -u 'un:pw' -H '_type: com.me.SSMessage' \
-d 'body={"url": "https://www.google.com"}' \
"http://localhost:8161/api/message/ssg? \
type=queue&clientId=consumerA&_type=com.me.SSMessage"
编辑:我无法测试,但我认为上面不需要 -H '_type: com.me.SSMessage'
...