Spring - 用于发送邮件的异步队列

发布于 2024-09-07 04:36:57 字数 727 浏览 12 评论 0 原文

我有这个:

 <si:poller max-messages-per-poll="10" id="defaultPoller" default="true">
  <si:interval-trigger interval="5000"/>
 </si:poller>
 <si:channel id="emailIn"/>
 <si:channel id="emailOut"/>

 <si:service-activator input-channel="emailIn" output-channel="emailOut" ref="mailService" method="recieveMessage"/>

 <si:gateway id="gateway" service-interface="com.blah.MailSender" default-request-channel="emailIn"/>

 <si:outbound-channel-adapter channel="emailOut" ref="mailService" method="recieveMessage" />

我认为我配置的是一个异步队列。我希望能够将消息放入其中,然后让另一个线程接收它们并稍后进行处理。然而,目前它似乎以同步方式进行。

我做错了吗(显然是的),但想知道这个配置中是否缺少某些东西,或者我是否只是采取了错误的方法?

干杯

I have this:

 <si:poller max-messages-per-poll="10" id="defaultPoller" default="true">
  <si:interval-trigger interval="5000"/>
 </si:poller>
 <si:channel id="emailIn"/>
 <si:channel id="emailOut"/>

 <si:service-activator input-channel="emailIn" output-channel="emailOut" ref="mailService" method="recieveMessage"/>

 <si:gateway id="gateway" service-interface="com.blah.MailSender" default-request-channel="emailIn"/>

 <si:outbound-channel-adapter channel="emailOut" ref="mailService" method="recieveMessage" />

And I thought what I was configuring was an async Queue. I want to be able to drop messages onto it, and have a nother thread pick them up and process then later. However, at the momment it seems to do it in a synchronous way.

Am i doing it wrong (obvioulsy yes), but wondering if there is something i'm missing in this config, or whether i just have the wrong approach?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-09-14 04:36:57

默认情况下,Spring Integration 中的所有通道都是同步的。这是一个有意识的设计决策,可以帮助您保持事务边界和安全上下文等。当您想要进行异步切换时,您应该将任务执行器添加到您的调度程序或将队列添加到您的通道:

<channel>
  <dispatcher task-executor="pool"/>
</channel>

<channel>
  <queue capacity="10"/>
</channel>

查看通道配置,了解有关调度程序和队列的一些详细信息。另请参阅 DirectChannel 部分以及该部分下方的 ExecutorChannel 部分。

By default all channels in Spring Integration are synchronous. This is a conscious design decision that will help you keep transaction boundaries and security contexts for example. When you want to do asynchronous hand-off you should add a task executor to your dispatcher or a queue to your channel:

<channel>
  <dispatcher task-executor="pool"/>
</channel>

<channel>
  <queue capacity="10"/>
</channel>

Look at channel configurations in the reference guide for some details on dispatchers and queues. See also the section on DirectChannel and the section on ExecutorChannel below that one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文