0

I use spring boot 2.2 application who receive mq message via jms.

Data is json

In my code I have this config

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

When I send data via IBM MQ Explorer, I get this error

    org.springframework.jms.support.converter.MessageConversionException: Could not find type id property [_type] on message

Is there a way to set this with IBM MQ explorer?

JoshMc
  • 10,239
  • 2
  • 19
  • 38
robert trudel
  • 5,283
  • 17
  • 72
  • 124
  • You might want to look at RFHUtil for sending anything more than a very simple test message. It sounds like you need to set a message property and RFHUtil should allow this. – JoshMc Dec 12 '19 at 16:11
  • If you have a sample message you want to replay already on a queue, you can use the `dmpmqmsg` utility to save it off and reload it, this will include the full message details including the message descriptor values and message properties. – JoshMc Dec 12 '19 at 16:32

1 Answers1

2

If your message doesn't have a property containing type information, you can subclass the MappingJackson2MessageConverter and override getJavaTypeForMessage

/**
 * Determine a Jackson JavaType for the given JMS Message,
 * typically parsing a type id message property.
 * <p>The default implementation parses the configured type id property name
 * and consults the configured type id mapping. This can be overridden with
 * a different strategy, e.g. doing some heuristics based on message origin.
 * @param message the JMS Message to set the type id on
 * @throws JMSException if thrown by JMS methods
 * @see #setTypeIdOnMessage(Object, javax.jms.Message)
 * @see #setTypeIdPropertyName(String)
 * @see #setTypeIdMappings(java.util.Map)
 */
protected JavaType getJavaTypeForMessage(Message message) throws JMSException {
Gary Russell
  • 166,535
  • 14
  • 146
  • 179