Question

I am able to set correlation id using <int:correlation-id /> tag but I want to set it from a POJO. So I tried

<int:header-enricher id="he" input-channel="in" output-channel="test">
    <int:correlation-id ref="heSimple" method="resolve" />
</int:header-enricher>

this doesnt works. CorrelationId is not modified. However if i change it to

<int:header-enricher id="he" input-channel="in" output-channel="test">
    <int:header name="foo" ref="heSimple" method="resolve" />
</int:header-enricher>

this works fine. So basically I can modify any other header key other than correlation id from this pojo. I also tried

<int:header-enricher id="he" input-channel="in" output-channel="test">
    <int:header name="correlationId" ref="heSimple" method="resolve" />
</int:header-enricher>

Interestingly that doesnt works either.

EDIT

private MessageChannel in;

in.send(MessageBuilder.withPayload("a1").build());
in.send(MessageBuilder.withPayload("b1").setCorrelationId("1").build());

somehow the problem seems to be related to setting the correlation id explicitly while sending the message. So in this case a1 message does ends up using the header enricher to set the new corelation id but the message b2 continue to use 1 as the correlation id.

Looking at debug logs it seems like a1 message is sent to transformer and invokes the header enricher but for message b2 the header enricher is not invoked

[11:44:23:052] [main] DEBUG o.s.i.t.MessageTransformingHandler - org.springframework.integration.transformer.MessageTransformingHandler#0 received message:    [Payload=a1][Headers={timestamp=1399045463050, id=d20d68e1-ea7a-df20-4faf-d1864855851c}] 
in hesimple for [Payload=a1][Headers={timestamp=1399045463050, id=d20d68e1-ea7a-df20-4faf-d1864855851c}]
[11:44:23:055] [main] DEBUG o.s.i.t.MessageTransformingHandler - handler 'org.springframework.integration.transformer.MessageTransformingHandler#0' sending reply Message: [Payload=a1][Headers={timestamp=1399045463055, id=3b72891c-aaa5-3570-7715-e020529b5f83, correlationId=test}] 

for message b1 header enricher is skipped

[11:44:23:056] [main] DEBUG o.s.i.t.MessageTransformingHandler - org.springframework.integration.transformer.MessageTransformingHandler#0 received message: [Payload=b1][Headers={timestamp=1399045463055, id=9aa2bb7e-9c6c-66e5-0d64-3afea4a57ee4, correlationId=1}] 
[11:44:23:056] [main] DEBUG o.s.i.t.MessageTransformingHandler - handler 'org.springframework.integration.transformer.MessageTransformingHandler#0' sending reply Message: [Payload=b1][Headers={timestamp=1399045463056, id=c8d54223-e506-727d-6bff-703755017403, correlationId=1}] 

there is not much in the header enricher

public static class HESimple {
    public String resolve(Message<String> message){
        System.out.println("in hesimple for " + message);
        return "test";
    }
}
Was it helpful?

Solution

I just tested the first case and it works just fine for me.

What version of Spring Integration are you using?

What is the signature of the method?

There is nothing "special" about that header that would cause the different behavior you describe. I suggest you turn on DEBUG logging to figure out what's happening.

EDIT:

In order to overwrite existing values, you need to set overwrite="true".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top