spring service-activator不适用于XML配置中的输出通道属性



从教程中了解spring集成基础知识,并尝试实现一个小型考试成绩处理程序。在下面的代码中,为input-channel="exam"调用了服务激活器,并且在同一服务激活器上设置的输出通道是output-channel="result",但它从未被调用,因此<int:outbound-channel-adapter>也从未被调用。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd">

<bean id="written" class="com.example.nora.service.ExamService"/>
<int:inbound-channel-adapter channel="exam" ref="hallticket" method="check">
<int:poller fixed-delay="1000"/>
</int:inbound-channel-adapter> 
<int:channel id="exam"/>

<int:service-activator input-channel="exam" output-channel="result" ref="written" method="write"/>
<int:service-activator input-channel="result" ref="sc" method="testScservice"/>
<int:outbound-channel-adapter channel="result" ref="resultServic" method="test">
</int:outbound-channel-adapter>
<int:channel id="result"/>

<bean id="hallticket" class="com.example.nora.service.Hallticket"/>
<bean id="resultServic" class="com.example.nora.service.ResultService"/>
<bean id="sc" class="com.example.nora.service.ScService"></bean>

</beans>

所以,基本上,它尝试从一个服务激活器上设置的输出通道调用另一个服务激活器。请让我理解这种行为。

首先,您的write方法必须返回将成为要发送到result通道的回复消息有效负载的东西。

其次,如果您希望在next服务激活器和出站通道适配器中处理该消息,则result通道必须是publish-subscribe-channel而不是默认情况下的直接通道。在当前的情况下,以循环方式处理消息,因此第一个消息发送到服务激活器,第二个消息发送到出站通道适配器,依此类推,在result通道中出现的每个消息上进行翻转。

查看有关这些通道的文档:

https://docs.spring.io/spring-integration/docs/current/reference/html/core.html channel-implementations-publishsubscribechannel

https://docs.spring.io/spring-integration/docs/current/reference/html/core.html channel-implementations-directchannel

最新更新