我的集成流程如下所示:
@Bean
public IntegrationFlow integrationFlow() {
return IntegrationFlows.from(Http.inboundGateway("/spring_integration_post")
.requestMapping(m -> m.methods(HttpMethod.POST))
.requestPayloadType(String.class))
.enrich(enricherSpec -> {
enricherSpec.header("correlationId", 1); //or ackCorrelationId ?
})
.split(s -> s.applySequence(false).get().getT2().setDelimiters(","))
.log()
.log()
.handle(Amqp.outboundAdapter(amqpTemplate())
.exchangeName("barrierExchange")
.routingKey("barrierKey"))
.get();
}
正如你所看到的,我在这里有丰富的内容:
.enrich(enricherSpec -> {
enricherSpec.header("correlationId", 1);
})
目前,它添加了带有常量值1
的 header correlationId
。但我想复制 messageId (id
) correlationId
。我不知道如何使用 DSL 来实现它。
我找到了有效的 xml 替代方案:
<int:header-enricher input-channel="receiveChannel" output-channel="processChannel">
<int:header name="ackCorrelation" expression="headers['id']" />
</int:header-enricher>
如何使用 java DSL 执行相同操作?
最佳答案
你为什么不读一下the documentation - Configuring a Header Enricher with the Java DSL和javadocs,而不是在这里继续问问题。你会取得更快的进步。
我们没有时间继续回答文档中已经涵盖的琐碎问题;我们的时间最好花在改进框架上。
文档中的示例:
@Bean
public IntegrationFlow enrichHeadersInFlow() {
return f -> f
...
.enrichHeaders(h -> h.header("emailUrl", this.emailUrl)
.headerExpression("from", "payload.from[0].toString()"))
.handle(...);
}
在您的情况下enricherSpec.headerExpression("ackCorrelation", "headers['id']")
关于java - 如何在Spring集成DSL中根据消息id丰富消息头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57704709/