S2201
S2201

Reputation: 1349

Spring Cloud Stream default custom message headers

Is there a way to configure the default Message<T> headers when the message is generated from the method return value:

@Publisher(channel = "theChannelname")
public MyObject someMethod(Object param) {
    ...
    return myObject;
}

or

@SendTo("theChannelname")
public MyObject someMethod(Object param) {
    ...
    return myObject;
}

In the examples above the Message<MyObject> will be automatically generated.

So, how can I control the default message generation?

Upvotes: 0

Views: 2118

Answers (2)

Artem Bilan
Artem Bilan

Reputation: 121282

You can do that via @Header annotation for the method arguments:

@Publisher(channel="testChannel")
public String defaultPayload(String fname, @Header("last") String lname) {
  return fname + " " + lname;
}

http://docs.spring.io/spring-integration/reference/html/message-publishing.html#publisher-annotation

Upvotes: 1

Marius Bogoevici
Marius Bogoevici

Reputation: 2410

Not really - the assumption is that if you return a payload then you don't care much about the headers. You can have the method return a Message and add your own headers there.

Upvotes: 2

Related Questions