Why are ID and TIMESTAMP declared as transient headers in Spring Integration?

我的梦境 提交于 2020-02-06 13:27:28

问题


I'm trying to send/receive messages via Spring Integration's AMQP in/outbound adapters and I'm facing this problem.

After finding Gary's answer here, I started to investigate if my app sets a message ID correctly. In fact, it's taken care of automatically here.

The producer looks like this.

I send a wrong message on purpose and at the consumer's end I watch its message transformer fail here.

After that the message gets re-queued and re-processed again endlessly.

While debugging this issue, I noticed that the ID of the sent and received messages are always different.

After debugging this event further, I learned that the standard ID field provided by Spring's core messaging framework is marked as transient and transient headers are never getting mapped.

Questions?

  • Why couldn't the framework automatically map MessageHeaders.ID to AmqpHeaders.MESSAGE_ID?
  • Should I mandate a custom headers field as an ID and implement MessageKeyGenerator?
  • BTW, how would I do that with the new Java DSL?

Many thanks!

Cheers, László


UPDATE: the cause of failed message being reprocessed in an infinite loop was caused by something else.

I've managed to fix that, by adding defaultRequeueRejected(false) to the AMQP inbound adapter's listener container config.

@Bean
public IntegrationFlow webhookInboundFlow(
    ConnectionFactory connectionFactory, ObjectMapper objectMapper,
    HeaderValueRouter webhookInboundRouter) {

  return IntegrationFlows
      .from(Amqp.inboundAdapter(connectionFactory, FORGETME_WEBHOOK_QUEUE_NAME)
          .configureContainer(s -> s.defaultRequeueRejected(false))
      )
      .log(INFO)
      .transform(new ObjectToJsonNodeTransformer(objectMapper))
      .route(webhookInboundRouter)
      .get();
}

回答1:


Why couldn't the framework automatically map MessageHeaders.ID to AmqpHeaders.MESSAGE_ID?

That's not a bad idea, at least as an option. Feel free to open an 'improvement' JIRA Issue.

Spring AMQP's AbstractMessageConverter has a property createMessageIds to generate a message id header; this is independent of Spring Integration.

So normally, if you want a message id header, you would set that property on the outbound adapter's RabbitTemplate.



来源:https://stackoverflow.com/questions/50544350/why-are-id-and-timestamp-declared-as-transient-headers-in-spring-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!