Web 服务集成 - 如何访问请求对象以响应 class?
web service integration - how to access request Object in response class?
我有访问网络服务的代码,然后 return 我回复了
<int:chain input-channel="balanceChannel" output-channel="processedItems">
<int-ws:outbound-gateway destination-provider="myDestinationProvider" />
</int:chain>
<int:service-activator input-channel="processedItems"
ref="responseHandler" method="handleResponse" output-channel="nativeQlChannel" />
我能够在我的 responseHandler 中获得响应,但我还想要使用通道发送到网络服务的请求对象?我如何在 responseHandler 中访问相同的请求对象?
好吧,由于所有 Spring 集成端点都通过通道相互分离,我们可以将它们视为微服务。这确实是合乎逻辑和自然的,那么下一个端点对前一个端点的输入一无所知。
反正我们可以通过消息headers达到要求。因此,您将请求负载复制到 headers 并在下游获取访问权限:
<int:header-enricher>
<int:header name="request" expression="payload"/>
</int:header-enricher>
您的服务方法 handleResponse
可以接受整个 Message<?>
来访问那个 headers 或者您可以只添加一个带有 @Header("request")
注释的方法参数。
我有访问网络服务的代码,然后 return 我回复了
<int:chain input-channel="balanceChannel" output-channel="processedItems">
<int-ws:outbound-gateway destination-provider="myDestinationProvider" />
</int:chain>
<int:service-activator input-channel="processedItems"
ref="responseHandler" method="handleResponse" output-channel="nativeQlChannel" />
我能够在我的 responseHandler 中获得响应,但我还想要使用通道发送到网络服务的请求对象?我如何在 responseHandler 中访问相同的请求对象?
好吧,由于所有 Spring 集成端点都通过通道相互分离,我们可以将它们视为微服务。这确实是合乎逻辑和自然的,那么下一个端点对前一个端点的输入一无所知。
反正我们可以通过消息headers达到要求。因此,您将请求负载复制到 headers 并在下游获取访问权限:
<int:header-enricher>
<int:header name="request" expression="payload"/>
</int:header-enricher>
您的服务方法 handleResponse
可以接受整个 Message<?>
来访问那个 headers 或者您可以只添加一个带有 @Header("request")
注释的方法参数。