巫师的蜕变

导航

 

现在有一个需求:

在发送端服务器出现故障后,接收端的接收方法要停下来,关于停止接收的方法,我做了下面这些事情:

// 获取 ConnectionFactory
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                "tcp://" + ip + ":61616");
// 创建 Connection
Connection connection = connectionFactory.createConnection();
connection.start();

//把connection放入map,方便停止
ConfigInfo.receiveSocket.put("connection", connection);
        System.out.println("connectionmap======"+ConfigInfo.receiveSocket.get("connection"));
// 创建 Session
Session session = connection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);

然后写了一个方法,停止接收 ,其实就是将connection关闭:

public static void stopReceivewebsite() throws JMSException{
        System.out.println("websiteimage开始停止方法");
        System.out.println(ConfigInfo.receiveSocket.get("connection"));
        Connection connection = (Connection) ConfigInfo.receiveSocket.get("connection");
        connection.close();
        System.out.println("websiteimage接收停止完成");
    }

 亲测好使。

posted on 2017-05-09 16:55  jacunjpg  阅读(2235)  评论(0编辑  收藏  举报