Spring Cloud Stream default custom message headers

ε祈祈猫儿з 提交于 2019-12-12 03:54:44

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/44571478/spring-cloud-stream-default-custom-message-headers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!