如何在野生蝇中依次使MDB消费

发布于 2025-01-18 16:58:08 字数 994 浏览 0 评论 0 原文

我正在关注本文创建JMS消息侦听器。一切都正确运行。当制作人发送消息时,听众可以识别新消息并开始做某事。

但是,当制作人同时发布多个消息时,听众也同时处理这些消息。如何使侦听器顺序运行?我希望它仅在成功处理上一条消息时才能处理下一条消息。 这是我的 Messagelistener

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "SendingSMSQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class SendgridEmail2SmsMessageListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        try {
            log.info("Receive {}", message);
            // Do some heavy things          
            Thread.sleep(2000);
            log.info("Finish");
        } catch (Exception e) {
            log.error("Listen message sending SMS failed", e);
        }
    }
}

I'm following this article to create a JMS message listener. Everything run correctly. When a producer sends a message the listener can recognize the new message and start doing something.

However, when the producer publishes multiple messages at the same time, the listener also handles these messages concurrently. How can I make the listener run sequentially? I want it to handle the next message only when the previous message is handled successfully.
This my my MessageListener:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "SendingSMSQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class SendgridEmail2SmsMessageListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        try {
            log.info("Receive {}", message);
            // Do some heavy things          
            Thread.sleep(2000);
            log.info("Finish");
        } catch (Exception e) {
            log.error("Listen message sending SMS failed", e);
        }
    }
}

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

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

发布评论

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

评论(1

煮茶煮酒煮时光 2025-01-25 16:58:08

经过数小时的研究,我发现有一个ActivationConfigproperty,可以让我们定义最大会议可以处理我们的请求,因此,就我而言,我只需要设置Maxsession是这样的:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "SendingSMSQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")
})
public class SendgridEmail2SmsMessageListener implements MessageListener {

有关更多信息:有关更多信息,请参考此页面

After hours of research, I found that there is an ActivationConfigProperty that allow us define the maximum sessions can handle our request, so in my case, I just need to set maxSession is 1 like this:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "SendingSMSQueue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")
})
public class SendgridEmail2SmsMessageListener implements MessageListener {

For more information, let reference this page https://docs.jboss.org/ejb3/docs/tutorial/1.0.7/html/Message_Driven_Beans.html

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