Spring integration 基于条件的EnrichHeader
我正在编写一个通用适配器,它从EMS获取消息并将其推入Kafka主题。如果配置文件中的某个特定标志设置为true,则必须充实标题。头的表达式也将存在于配置文件中Spring integration 基于条件的EnrichHeader,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我正在编写一个通用适配器,它从EMS获取消息并将其推入Kafka主题。如果配置文件中的某个特定标志设置为true,则必须充实标题。头的表达式也将存在于配置文件中 return IntegrationFlows.from(org.springframework.integration.jms.dsl.Jms .messageDrivenChannelAdapter(org.springframework.integration.jms.dsl.Jms
return IntegrationFlows.from(org.springframework.integration.jms.dsl.Jms
.messageDrivenChannelAdapter(org.springframework.integration.jms.dsl.Jms
.container(this.queueConnFactory, this.queue)
.transactionManager(transactionManager()).get()))
.enrichHeaders(
h -> h.headerExpression(KafkaHeaders.MESSAGE_KEY, "headers['flightNbr']"))
.handle(Kafka.outboundChannelAdapter(kafkaTemplate).topic(kafkaTopic))
.get();
我知道如何从收到的消息中添加标题,但我们如何有条件地添加标题?
此外,如果标志为false,则不会应用标题 有一个headerFunctionString名称,即Function函数,而不是headerExpression。所以,像这样的东西应该适合你:
.enrichHeaders(h ->
h.headerFunction(KafkaHeaders.MESSAGE_KEY, m -> {
if (SOME_STATE) {
return m.getHeaders().get("flightNbr");
}
else {
return null;
}
}))