【问题标题】:Type Id property error is get when sending text发送文本时出现类型 ID 属性错误
【发布时间】:2019-12-13 00:37:29
【问题描述】:

我使用通过 jms 接收 mq 消息的 spring boot 2.2 应用程序。

数据是json

在我的代码中我有这个配置

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

当我通过 IBM MQ Explorer 发送数据时,我收到此错误

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

有没有办法使用 IBM MQ 资源管理器进行设置?

【问题讨论】:

  • 您可能希望查看 RFHUtil 发送的不仅仅是非常简单的测试消息。听起来您需要设置一个消息属性,RFHUtil 应该允许这样做。
  • 如果您已经在队列中有想要重播的示例消息,您可以使用dmpmqmsg 实用程序将其保存并重新加载,这将包括完整的消息详细信息,包括消息描述符值和消息属性。

标签: spring-boot ibm-mq spring-messaging


【解决方案1】:

如果您的消息没有包含类型信息的属性,您可以继承 MappingJackson2MessageConverter 并覆盖 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 {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 2016-05-12
    • 1970-01-01
    • 2020-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多