【问题标题】:How to put a msg to queue as json format using Spring Integration AMQP如何使用 Spring Integration AMQP 将 msg 以 json 格式放入队列
【发布时间】:2017-05-19 07:21:30
【问题描述】:

目前我正在尝试使用 json 格式将消息放入队列。下面是我的代码 sn-p 但它不起作用。

return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, NOTE_INCOMING_QUEUE)
                .concurrentConsumers(2))
                .transform(new JsonToObjectTransformer(Note.class))
                .handle(Note.class, (note, header) -> {
                    // doing something
                    return note;
                })
                .channel(Amqp.channel(connectionFactory).queueName(NOTE_OCRED_QUEUE).messageConverter(
                        new MappingJackson2MessageConverter()))
                .get();

消息作为 application/x-java-serialized-object 放入队列中。

【问题讨论】:

    标签: spring-integration spring-integration-amqp spring-integration-dsl


    【解决方案1】:

    两个问题:

    1. AMQP 支持的通道用于持久性,而不是简单地向 RabbitMQ 发送消息;默认情况下,整个消息是序列化的(使用 RabbitTemplate 的转换器,而不是通道的)。
    2. 通道上的消息转换器仅在通道上用于转换 DataType,而不用于序列化。

    使用出站通道适配器...

    .handle(Amqp.outboundAdapter(rabbitTemplate).routingKey(NOTE_OCRED_QUEUE));
    

    其中RabbitTemplate 配置了Jackson2JsonMessageConverter

    【讨论】:

      猜你喜欢
      • 2014-07-28
      • 1970-01-01
      • 2020-07-27
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      相关资源
      最近更新 更多