将JMS侦听器重新连接到JBossMQ [英] Reconnecting JMS listener to JBossMQ

查看:125
本文介绍了将JMS侦听器重新连接到JBossMQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Java监听器,它从JBossMQ中的队列中读取文本消息。如果我们必须重新启动JBoss,监听器将不会重新连接并再次开始读取消息。我们每隔2分钟就会在侦听器的日志文件中收到消息,说它无法连接。我们的代码或JBossMQ中是否有设置?我是JMS的新手,所以任何帮助都将不胜感激。谢谢。

We have a Java listener that reads text messages off of a queue in JBossMQ. If we have to reboot JBoss, the listener will not reconnect and start reading messages again. We just get messages in the listener's log file every 2 minutes saying it can't connect. Is there something we're not setting in our code or in JBossMQ? I'm new to JMS so any help will be greatly appreciated. Thanks.

推荐答案

您应该在客户端代码中实现javax.jms.ExceptionListener。您将需要一个名为onException的方法。当客户端的连接丢失时,您应该获得JMSException,并且将自动调用此方法。您唯一需要注意的是,如果您故意断开与JBossMQ的连接 - 这也会引发异常。

You should implement in your client code javax.jms.ExceptionListener. You will need a method called onException. When the client's connection is lost, you should get a JMSException, and this method will be called automatically. The only thing you have to look out for is if you are intentionally disconnecting from JBossMQ-- that will also throw an exception.

某些代码可能如下所示:

Some code might look like this:

    public void onException (JMSException jsme)
    {
        if (!closeRequested)
        {
            this.disconnect();
            this.establishConnection(connectionProps, queueName, uname, pword, clientID, messageSelector);
        }        
        else
        {
            //Client requested close so do not try to reconnect
        }
    }

在establishConnection代码中,您将实现 while(!initialized)构造其中包含try / catch。在您确定已正确连接和订阅之前,请留在while循环中捕获所有JMS / Naming / etc.例外。

In your "establishConnection" code, you would then implement a while(!initialized) construct that contains a try/catch inside of it. Until you are sure you have connected and subscribed properly, stay inside the while loop catching all JMS/Naming/etc. exceptions.

我们已经使用这种方法多年来使用JBossMQ并且效果很好。我们的JMS客户端在弹回JBossMQ或丢失网络连接后没有重新连接,我们从未遇到过问题。

We've used this method for years with JBossMQ and it works great. We have never had a problem with our JMS clients not reconnecting after bouncing JBossMQ or losing our network connection.

这篇关于将JMS侦听器重新连接到JBossMQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆