Search code examples
javaspringspring-bootspring-jms

Spring Boot JMS MappingJackson2MessageConverter cannot find `_type` field even though it exists


I'm using Spring boot to receive JMS message and cURL to send it.

Here's the Spring config:

@Bean
public MessageConverter jsonJmsMessageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}

When I try to send a message, I get:

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]

My cURL command is:

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 is set, both as a header (I don't think this is right) and as a field in the JSON. Why do I get that error from the Spring app?


Solution

  • This is more an Activemq/REST question than Spring:

    converter.setTypeIdPropertyName("_type");

    This sets a JMS Message property, it is not a field in the message. The stuff about message headers is here: https://docs.oracle.com/javaee/7/api/javax/jms/Message.html

    The trick is how to do this with the Activemq REST interface (and thus CURL). The answer is to add it as a GET parameter on the query:

    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"
    

    Edit: I can't test it, but I don't think the -H '_type: com.me.SSMessage' is needed above...