简体   繁体   English

Spring Integration Proxy Gateway上的入站变压器

[英]Inbound Transformer on Spring Integration Proxy Gateway

I'd like to configure a process that looks something like: 我想配置一个看起来像这样的过程:

Method Call -> Dynamic Proxy Gateway -> Channel -> Service Activator -> Method Call
             ^---------- Transformer <- Channel <-             [return value]

Effectively, I'd like to somehow access the hidden channel Spring Integration creates and transform the return message payload into a different message type. 实际上,我想以某种方式访问​​Spring Integration创建的隐藏通道,并将返回消息有效负载转换为其他消息类型。

A simple solution may at first appear to be configuring a default-reply-channel on the gateway, the issue is that I'm sharing the channel between bundles using OSGi. 首先,一个简单的解决方案似乎是在网关上配置默认回复通道,问题是我正在使用OSGi在捆绑包之间共享通道。 The Service Activator is provided by Bundle "B", and offers a shared channel for incoming requests (it acts as a data provider service). 服务激活器由捆绑软件“ B”提供,并为传入的请求提供共享通道(充当数据提供者服务)。 Bundle "A" requires some data, so it requests it, but needs the result in an alternate format. 捆绑软件“ A”需要一些数据,因此它会请求它,但是需要使用备用格式的结果。 Note that if Bundle "B" were to be able to use the default-reply-channel specified by Bundle "A" then Bundle "A" must share it. 请注意,如果捆绑软件“ B”能够使用捆绑软件“ A”指定的默认回复通道,则捆绑软件“ A”必须共享它。 That's all fair and well, but then I have a circular dependency in OSGi, and nothing would start. 一切都很好,但是后来我在OSGi中有了循环依赖,什么也不会开始。

It seems like another solution here would be to define an output-channel on the Service Activator, but this suffers from a slightly different problem. 似乎这里的另一个解决方案是在Service Activator上定义一个输出通道,但这遇到了一个稍微不同的问题。 Assuming I share the output-channel from Bundle "B" I've mitigated the circular dependency issue, but now anytime someone requests something from Bundle "A" the reply goes to everyone attached to the output channel -- this, too, is undesirable. 假设我共享了捆绑软件“ B”的输出通道,我已经缓解了循环依赖问题,但是现在任何时候有人从捆绑软件“ A”请求某项内容时,回复都会发送给附加到输出通道的每个人,这也是不可取的。

[ Edit : What I mean here is that if "B" shares both an input and an output channel for its service activator then anyone bound to "B"'s output channel will receive the result of anyone's request to "B"'s input channel -- and the desired behavior is that the replies are directed at the requestors. [ 编辑 :我的意思是,如果“ B”共享其服务激活程序的输入和输出通道,那么绑定到“ B”输出通道的任何人都会收到任何人请求“ B”输入的结果通道-期望的行为是将答复定向到请求者。

I should note that the transformer here makes sense only in the context of Bundle A. Bundle B provides a service (for all intents and purposes one that I have no control over). 我应该注意,这里的转换器仅在Bundle A的上下文中才有意义。Bundle提供了一种服务(出于所有意图和目的,我无法控制)。 The transformation, specific to the needs of Bundle A should reside in Bundle A.] 特定于捆绑软件A需求的转换应位于捆绑软件A中。]

So, what I think I really need is to be able to configure a transformer on replies to a dynamic proxy gateway, but try as I might I can't find such a device in the Spring Integration manual. 因此,我认为我真正需要的是能够在对动态代理网关的答复上配置一个转换器,但是请尝试一下,因为我可能在Spring Integration手册中找不到这样的设备。 As always, help would be greatly appreciated. 一如既往,我们将不胜感激。

-- -

Edit 2 : I attempted two other tactics here: 编辑2 :我在这里尝试了另外两种策略:

  1. Use a service-activator that refers to the OSGi shared channel from Bundle B 使用服务激活器,该服务激活器引用捆绑软件B中的OSGi共享通道

    The result was that the returned element was a GenericMessageType -- which it could be possible to transform. 结果是返回的元素是GenericMessageType,可以转换它。 The GenericMessageType is really the boolean result of the "send" method which the service-activator must point to, not the reply message. GenericMessageType实际上是服务激活程序必须指向的“发送”方法的布尔结果,而不是回复消息。 So this method does not work. 所以这个方法不起作用

  2. Use a header-enricher to set REPLY_CHANNEL and pass the reply channel as a reference rather than a value. 使用标题增强器设置REPLY_CHANNEL并将答复通道作为参考而不是值传递。

    This technique did not work, the REPLY_CHANNEL header element appears to be ignored when the default-reply-channel of the gateway is set (and the default-reply-channel must be set). 此技术无效 ,设置网关的默认回复通道(并且必须设置默认回复通道)时,REPLY_CHANNEL标头元素似乎被忽略。

In theory the real answer here is to use a chain. 从理论上讲,这里的真正答案是使用链。

The configuration for Bundle A will look something like 捆绑软件A的配置类似于

<si:gateway id="gw" default-request-channel="xyz" />
<si:channel id="xyz" />
<si:chain input-channel="xyz" />
    <si:service-activator />
    <si:transformer />
</si:chain>

Note for Bundle B the configuration is unchanged and only a single channel is shared through OSGi for access by Bundle A or any tertiary bundles. 请注意,对于捆绑软件B,配置不变,并且仅单个通道通过OSGi共享以供捆绑软件A或任何第三捆绑软件访问。

Two options for the service-activator are available: 服务激活器有两个选项:

  1. Shared service through OSGi 通过OSGi共享服务
  2. Custom service that simply invokes a proxy-gateway for the pre-transformation returned data type. 简单地为转换前返回的数据类型调用代理网关的定制服务。

The proxy-gateway in Bundle A will inject into some input-channel "xyz" and ultimately the implied return channel will contained the transformed content as desired. 捆绑软件A中的代理网关将注入某些输入通道“ xyz”,并且最终隐含的返回通道将包含所需的转换内容。

This solution is nearly the same as the one proposed by SingleShot, however here we prevent the sharing of a real service through OSGi, maintaining bundle boundaries. 该解决方案与SingleShot提出的解决方案几乎相同,但是在这里,我们阻止通过OSGi共享真实服务,并保持包边界。

I'm a bit confused by your problem description. 您的问题描述让我有些困惑。 I understand the circular dependency aspect, and the transformer aspect, but I'm not so sure about "the reply goes to everyone attached to A". 我了解循环依赖方面和转换器方面,但是我不确定“答复将传递给附加到A的每个人”。

It kind of sounds like you might want to have two service activators for B. Your existing one in B would stay, and most clients would use it. 听起来好像您可能想要为B提供两个服务激活器。您在B中现有的服务激活器将保留下来,大多数客户都将使用它。 The other one would go in A, and would only use channels defined in A. This would prevent requests from A to B from resulting in responses being received by components outside A. 另一个将进入A,并且仅使用A中定义的通道。这将防止A到B的请求导致A外部的组件收到响应。

This should make the problem of transformation easier. 这应该使转换问题更容易。 Transformers take a message from one channel, transform it, and place it on another. 变形金刚从一个通道中获取一条消息,对其进行转换,然后将其放置在另一个通道上。 Just add one in A and you should be good. 只需在A中添加一个就可以了。

So in A you would have these components, only useable by A: 因此,在A中,您将拥有这些组件,仅可由A使用:

  • a gateway 一个网关
  • an input channel 输入通道
  • a service activator for B B的服务激活器
  • an output channel 输出通道
  • a transformer 变压器
  • a transformed output channel 转换后的输出通道

In B you would have, useable by anyone: 在B中,任何人都可以使用:

  • an input channel 输入通道
  • a service activator for B B的服务激活器
  • an output channel 输出通道

A depends on B, but B does not depend on A. A取决于B,但B不取决于A。

Will that work? 那行得通吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM