问题描述
我需要在我的 Spring 集成上下文中将消息动态分配给 MessageChannel.当我知道我想要的 MessageChannel 的名称时,我可以通过从上下文中获取 MessageChannel bean 来做到这一点.
I need to dynamically assign messages to MessageChannels in my Spring Integration Context.I can do this by getting the MessageChannel bean from the context when I know the names of the MessageChannel I want.
我需要做的是以编程方式找到在我的 ChannelAdapter/Service 中设置的消息通道的名称/ID.
What I need to do is programatically find the name/id of the message channel(s) that are set in my ChannelAdapter/Service.
但是,MessageChannel API 没有与之关联的 getName() 或 getId() 方法.
However, the MessageChannel API does not have a getName() or getId() method associated with it.
有没有办法找到这条信息?
Is there a way to find this piece of information?
提前致谢.
推荐答案
让我们换个角度看这个任务!
Let's take look at this task from other side!
处理像通道这样的低 API 的原因是什么?
What is the reason to get deal with such low API like channels?
为什么不使用 Router
模式就这么回事?
Why just don't use the Router
pattern on the matter?
如果我理解正确,您希望有一些动态路由,您可以在其中通过某些 Message
属性确定目标通道.
If I understand correctly, you want to have some dinamic routing, where you determine a destination channel by some Message
property.
因此,使用 expression
路由器可能就足够了:
So it might be enough just use an expression
router:
<int:router input-channel="input" expression="payload.theChannel"/>
这篇关于Spring 集成 MessageChannel ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!