亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Java調用ActiveMQ簡單范例的代碼

發布時間:2020-07-14 11:36:01 來源:網絡 閱讀:333 作者:Dmimi 欄目:編程語言

如下的內容是關于Java調用ActiveMQ簡單范例的內容,應該能對大伙有所用。

package jms;  

import javax.jms.Connection;  
import javax.jms.DeliveryMode;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.MessageProducer;  
import javax.jms.Session;  
import javax.jms.TextMessage;  

import org.apache.activemq.ActiveMQConnectionFactory;  
import org.apache.activemq.broker.BrokerService;  
import org.apache.log4j.PropertyConfigurator;  

public class PTP_sends {  

    public PTP_sends(){  

    }  

    private Connection connection;  
    private String subject = "TOOL.DEFAULT";  

    public void send(String msg){  

        try {  
            connection=connectionFactory.createConnection();  
            connection.start();  
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);  
            Destination destination=session.createQueue(subject);  
            MessageProducer producer=session.createProducer(destination);  
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);  
            TextMessage message = session.createTextMessage(msg);  

            producer.send(message);  
            System.out.println("消息已經發送。。。。");  

            message.clearProperties();  
            session.close();  
            connection.stop();  
            connection.close();  
            System.out.println("關閉資源。。。。");  
        } catch (JMSException e) {  
            e.printStackTrace();  
        }  
    }  

    public static void main(String[] args) {  
        PropertyConfigurator.configure("c:\log4j.properties");  

        PTP_sends ptpSends=new PTP_sends();  
        ptpSends.send("this is JMS .....");  
    }  

}  

package jms;  

import javax.jms.Connection;  
import javax.jms.Destination;  
import javax.jms.JMSException;  
import javax.jms.Message;  
import javax.jms.MessageConsumer;  
import javax.jms.Session;  
import javax.jms.TextMessage;  

import org.apache.activemq.ActiveMQConnectionFactory;  
import org.apache.log4j.PropertyConfigurator;  

public class PTP_receive {  

    private Connection connection;  
    private String subject = "TOOL.DEFAULT";  

     public void receive(){  
            ActiveMQConnectionFactory connectionFactory =new ActiveMQConnectionFactory();  
            try {  
                connection=connectionFactory.createConnection();  
                connection.start();  
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);  
                Destination destination=session.createQueue(subject);  
                MessageConsumer consumer=session.createConsumer(destination);  
                System.out.println("同步接受消息:");  
                Message message=consumer.receive();  
                System.out.println("n收到的message 是:"+((TextMessage)message).getText());  

                message.clearProperties();  
                consumer.close();  
                session.close();  
                connection.stop();  
                connection.close();  
                System.out.println("關閉資源。。。。");  
            } catch (JMSException e) {  
                e.printStackTrace();  
            }  
        }  

    public static void main(String[] args) {  
        PropertyConfigurator.configure("c:\log4j.properties");  
        PTP_receive receive=new PTP_receive();  
        receive.receive();  
    }  

}  
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

饶平县| 建宁县| 沁源县| 荥经县| 林周县| 灯塔市| 沈阳市| 盐源县| 项城市| 石阡县| 封开县| 会昌县| 绥江县| 兴化市| 吴川市| 修文县| 丰宁| 新丰县| 仁寿县| 大丰市| 遂溪县| 勐海县| 元阳县| 昭觉县| 喀什市| 余庆县| 宜君县| 太康县| 望奎县| 延庆县| 壤塘县| 泌阳县| 宁阳县| 西贡区| 理塘县| 中阳县| 桐柏县| 大厂| 阿拉善左旗| 广南县| 湟中县|