224.6.5. スケジュールされたポーリングの例
このコンポーネントはスケジュールされたポーリングをサポートするため、ポーリングコンシューマーとして使用できます。たとえば、1 分ごとにデータベースをポーリングするには、以下のコマンドを実行します。
from("mybatis:selectAllAccounts?delay=60000").to("activemq:queue:allAccounts");
from("mybatis:selectAllAccounts?delay=60000").to("activemq:queue:allAccounts");
その他のオプションは、「Polling Consumer Options」の「ScheduledPollConsumer Options」を参照してください。
または、Timer や Quartz コンポーネントなどのスケジュールされたポーリングをトリガーする別のメカニズムを使用することもできます。 以下の例では、Timer コンポーネントを使用して 30 秒ごとにデータベースをポーリングし、データを 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>