问题
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
toAmqpHeaders.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