我正在努力实现一个缓冲区,以便执行各种作业。 我正在开发一个基于 Spring 的项目。 我决定使用 Spring Integration 来实现我的目标。我通过了一个 Cafè 示例项目来了解 SI 的工作原理。
为了演示 Spring Integration,我实现了一个表,在其中动态插入要执行的作业。 该表是“网关”。然后我配置了路由器和各种 channel 。
我不完全理解的是轮询器元素必须检查“网关”中是否存在新作业。 这是正确的吗?
如果是这样,我该如何配置轮询器? 提前致谢! 这里是 xml 代码:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-feed="http://www.springframework.org/schema/integration/feed"
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<int:gateway id="usersToSend" service-interface="it.stasbranger.spidly.rss.UsersToSend" />
<int:channel id="channel" />
<int:channel id="providers"/>
<int:router input-channel="providers" ref="providerRouter" method="resolveProviderChannel"/>
<int:channel id="twitterChannel">
<int:queue capacity="10"/>
</int:channel>
<int:service-activator input-channel="twitterChannel" ref="twitterService" method="updateStatusByProfile"/>
<int:channel id="facebookChannel">
<int:queue capacity="10"/>
</int:channel>
<int:service-activator input-channel="facebookChannel" ref="facebookService" method="updateStatusByProfile"/>
<int:channel id="linkedinChannel">
<int:queue capacity="10"/>
</int:channel>
<int:service-activator input-channel="linkedinChannel" ref="linkedinService" method="writeSlogan2Linkedin"/>
<bean id="twitterService" class="it.social.TwitterService"/>
<bean id="facebookService" class="it.social.FacebookService"/>
<bean id="linkedinService" class="it.social.LinkedinService"/>
<int:poller id="poller" default="true">
</int:poller>
最佳答案
<gateway/>
不会被轮询,它们是“消息驱动的”,因为调用者使用网关将消息“发送”到流中。
对于轮询场景,请使用 <int:inbound-channel-adapter/>
它轮询一个方法(按照轮询器的时间表)寻找要做的工作。
如果该方法返回 null,则轮询器将返回 sleep 状态(直到下一次触发)。如果该方法返回一个值,则消息将发送到 channel 。
关于java - 将 Spring Integration 中的轮询器配置为队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16588648/