235.7.5. 调度的轮询示例
此组件支持调度的轮询,因此可用作轮询消费者。例如,要每分钟轮询数据库:
from("mybatis:selectAllAccounts?delay=60000") .to("activemq:queue:allAccounts");
from("mybatis:selectAllAccounts?delay=60000")
.to("activemq:queue:allAccounts");
如需了解更多选项,请参阅 Polling Consumer 上的"ScheduledPollConsumer Options"。
另外,您可以使用另一种机制来触发调度的轮询,如 Timer 或 Quartz 组件。 在以下示例中,我们轮询数据库,每 30 秒使用 Timer 组件并将数据发送到 JMS 队列:
from("timer://pollTheDatabase?delay=30000") .to("mybatis:selectAllAccounts") .to("activemq:queue:allAccounts");
from("timer://pollTheDatabase?delay=30000")
.to("mybatis:selectAllAccounts")
.to("activemq:queue:allAccounts");
以及使用的 MyBatis SQL 映射文件:
<!-- Select with no parameters using the result map for Account class. --> <select id="selectAllAccounts" resultMap="AccountResult"> select * from ACCOUNT </select>
<!-- Select with no parameters using the result map for Account class. -->
<select id="selectAllAccounts" resultMap="AccountResult">
select * from ACCOUNT
</select>