Spring Cloud Stream 默认自定义消息头 [英] Spring Cloud Stream default custom message headers

查看:40
本文介绍了Spring Cloud Stream 默认自定义消息头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从方法返回值生成消息时,有没有办法配置默认的Message标头:

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;
}

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

在上面的示例中,Message 将自动生成.

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

那么,如何控制默认消息生成?

So, how can I control the default message generation?

推荐答案

您可以通过方法参数的 @Header 注释来做到这一点:

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

这篇关于Spring Cloud Stream 默认自定义消息头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆