Spring integration 是否可以在spring集成中覆盖消息头id的值?

Spring integration 是否可以在spring集成中覆盖消息头id的值?,spring-integration,spring,Spring Integration,Spring,我使用的是来自的声明检查模式,但我希望使用自定义ID存储消息。这应该很容易,因为消息存储实现使用传入消息头ID存储消息。是否可以使用标题充实器或/和标题过滤器覆盖消息标题id的值 消息头id和消息存储 SimpleMessageStore以及JdbcMessageStore正在使用传入消息ID来存储消息。在addMessage方法中(示例来自SimpleMessageStore),我们有: 要拥有自定义ID,在声明签入之前拥有一个标头enricher就足够了,其中ID标头的值将替换为自定义值。例

我使用的是来自的声明检查模式,但我希望使用自定义ID存储消息。这应该很容易,因为消息存储实现使用传入消息头ID存储消息。是否可以使用标题充实器或/和标题过滤器覆盖消息标题id的值

消息头id和消息存储
SimpleMessageStore
以及
JdbcMessageStore
正在使用传入消息ID来存储消息。在
addMessage
方法中(示例来自
SimpleMessageStore
),我们有:

要拥有自定义ID,在声明签入之前拥有一个标头enricher就足够了,其中ID标头的值将替换为自定义值。例如:

<int:header-enricher input-channel="gateDocCheckInReqChannel" 
    output-channel="gateDocCheckInEnrichedChannel">
    <int:header name="id" expression="payload.getDocumentID()" overwrite="true" />
</int:header-enricher>
<int:claim-check-in input-channel="gateDocCheckInEnrichedChannel" 
    output-channel="gateDocCheckInReplyChannel" message-store="messageStore" />

它不起作用;消息头id不会被覆盖。我尝试在标题充实器之前在ID上使用标题过滤器,但它也不起作用

相关的 我发现了这篇关于删除某些内部逻辑撤消的标题字段的老文章:

此外,在撤消头删除的消息处理程序上还有一个已解决的问题INT-923

据推测,标题过滤器上的问题INT-1135修复了此行为

实际上,
ID
时间戳
头是只读的(
MessageHeaderAccessor
):

它们是为具体的
消息指定的,该消息是不可变的

这些标头是为框架中的内部使用而设计的,不能更改

对于像您这样的用例,需要引入addition
businessKey
,并且不考虑那些interlan头来处理它

既然您说您希望在
声明ckeck
之后,通过存储中的
ID
以某种方式确定消息,我建议您使用
元数据存储
来保留
ID businessKey
对,以便将来能够以某种方式还原它们

当然,您可以尝试针对您的特定用例使用
MutableMessageBuilder

MutableMessageBuilder.fromMessage(message)
            .setHeader(MessageHeaders.ID, UUID.randomUUID())
            .build()
但无论如何,
ID
必须是
UUID

右:
HeaderFilter
也不会删除那些只读头。

我已经通过如下操作覆盖了http\U请求方法。接下来的请求是Post,我已经从标题中删除了它并添加了PUT。
I have overridden the http_requestMethod by doing as like below. The request coming is Post which I have removed from Headers and added PUT.


<int:header-filter input-channel="headerFilterChannel"
        header-names="http_requestMethod" output-channel="closeAndCloneOldTasksHeaderEnricherChannel" />

    <int:header-enricher input-channel="closeAndCloneOldTasksHeaderEnricherChannel"
        output-channel="caresToSfdc">
        <int:header name="http_requestMethod" value="PUT" />
    </int:header-enricher>

***Before Overriding Log*** 
GenericMessage [payload=com.cardinalhealth.chh.exception.model.GenericResponse@1948829c, headers={http_requestMethod=POST, replyChannel=org.springframework.messag

**After  Overriding Log :**
GenericResponse@142cd5fd, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@5710c249, http_requestMethod=PUT, 
***在覆盖日志之前*** GenericMessage[payload=com.cardinalhealth.chh.exception.model。GenericResponse@1948829c,headers={http_requestMethod=POST,replyChannel=org.springframework.messag **重写日志后:** GenericResponse@142cd5fd,headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@5710c249,http_requestMethod=PUT,
MutableMessageBuilder.fromMessage(message)
            .setHeader(MessageHeaders.ID, UUID.randomUUID())
            .build()
I have overridden the http_requestMethod by doing as like below. The request coming is Post which I have removed from Headers and added PUT.


<int:header-filter input-channel="headerFilterChannel"
        header-names="http_requestMethod" output-channel="closeAndCloneOldTasksHeaderEnricherChannel" />

    <int:header-enricher input-channel="closeAndCloneOldTasksHeaderEnricherChannel"
        output-channel="caresToSfdc">
        <int:header name="http_requestMethod" value="PUT" />
    </int:header-enricher>

***Before Overriding Log*** 
GenericMessage [payload=com.cardinalhealth.chh.exception.model.GenericResponse@1948829c, headers={http_requestMethod=POST, replyChannel=org.springframework.messag

**After  Overriding Log :**
GenericResponse@142cd5fd, headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@5710c249, http_requestMethod=PUT,