java inthttp:具有可轮询请求通道的inboundgateway
我正在浏览一些基于spring集成的代码,我注意到所有int http:inbound网关都使用可轮询的请求通道:
<int-http:inbound-gateway id="someId"
request-channel="queue-channel"
reply-channel="reply-channel"
request-payload-type="java.lang.String"
supported-methods="POST"
path="/rest/notifications"
auto-startup="true" />
<int:channel id="queue-channel" datatype="java.lang.String">
<int:queue capacity="100" />
</int:channel>
配置中指定了显式轮询器:
<int:poller id="mainSystemPoller" default="true" fixed-delay="500" max-messages-per-poll="1">
<int:transactional transaction-manager="transactionManager" propagation="REQUIRES_NEW" isolation="DEFAULT"/>
</int:poller>
因此,流上的第一个通道是可轮询的。使用这种方法的好处是什么?它是否只是在业务流(事务配置、队列容量等)方面给了我们更多的灵活性
# 1 楼答案
如果没有事务配置,使用轮询器就没有什么价值,因为http线程无论如何都会在网关中等待应答
但是,在您的情况下,它将启动一个事务,并导致网关下游的所有内容在一个事务中运行。但是,按照配置,这将使您的请求成为单线程;您需要一个任务执行器来处理多个并发请求
还有其他方法可以在事务中运行并发web请求;您可以改用事务网关,然后流将在web容器线程上运行,并发性由web容器管理