91在线公开视频_全黄特一级_www.亚洲天堂网_杏导航aⅴ福利网站_久久久综合网_大又大粗又爽又黄少妇毛片

18842388900

網(wǎng)站建設(shè) APP開發(fā) 小程序

Article/文章

記錄成長點(diǎn)滴 分享您我感悟

您當(dāng)前位置>首頁 > 知識(shí) > 軟件開發(fā)

如何使用ActiveMQ測(cè)試小程序

發(fā)表時(shí)間:2019-05-20 08:50:47

文章來源:沈陽網(wǎng)站建設(shè)

標(biāo)簽:active MQ

分享:

瀏覽次數(shù):0

介紹 Active MQ是個(gè)消息隊(duì)列管理器,用于通訊的中間件。現(xiàn)在由我來給大家介紹一下如何使用ActiveMQ測(cè)試小程序

首先需要下載ActiveMQ,并修改內(nèi)存

修改bin目錄下activemq.bat
在最后一行加入

set ACTIVEMQ_OPTS=-Xms1G -Xmx1G

保存后執(zhí)行該bat文件
新建maven項(xiàng)目
pom文件中加入依賴

<dependencies>        <dependency>            <groupId>org.apache.activemq</groupId>            <artifactId>activemq-all</artifactId>            <!--我的mq版本為5.9.0-->            <version>5.9.0</version>        </dependency>        <!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-broker -->        <dependency>            <groupId>org.apache.activemq</groupId>            <artifactId>activemq-broker</artifactId>            <version>5.10.0</version>        </dependency>        <!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-client -->        <dependency>            <groupId>org.apache.activemq</groupId>            <artifactId>activemq-client</artifactId>   設(shè)計(jì)軟件

<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>沈陽<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>軟件開發(fā)</a></a>,<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>沈陽<a href=http://www.www.fjxmxtpower.cn target=_blank class=infotextkey>軟件公司</a></a>

<version>5.14.0</version> </dependency> </dependencies>

發(fā)送端程序

import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;import javax.jms.*;public class Send {   // private static final int SEND_NUMBER = 10;    public static void main(String[] args){        //ConnectionFactory:連接工廠,JMS用它創(chuàng)建連接        ConnectionFactory connectionFactory;        //Connection:JMS客戶端到JMS Provider的連接        Connection connection = null;        //Session:一個(gè)發(fā)送或接收消息的線程        Session session;        //Destination:消息的目的地;消息的接收者        Destination destination;        //MessageProducer:消息發(fā)送者        MessageProducer producer;        //TextMessage message;        //構(gòu)造ConnectionFactory實(shí)例對(duì)象,此處采用ActiveMQ的實(shí)現(xiàn)jar        connectionFactory = new ActiveMQConnectionFactory(                ActiveMQConnection.DEFAULT_USER,                ActiveMQConnection.DEFAULT_PASSWORD,                "tcp://www.www.fjxmxtpower.cn:61616"        );        try{            //構(gòu)造從工廠得到連接對(duì)象            connection = connectionFactory.createConnection();                        //匯海            connection.start();                       //獲取操作連接            session = connection.createSession(Boolean.TRUE,                    Session.AUTO_ACKNOWLEDGE);                         //獲取session注意參數(shù)值test是一個(gè)服務(wù)器的queue,須在ActiveMQ的console配置            destination = session.createQueue("test");                        //得到發(fā)送者            producer = session.createProducer(destination);                        //設(shè)置不持久化,實(shí)際情況請(qǐng)根據(jù)項(xiàng)目決定            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);                        //構(gòu)造消息,這里寫死了,項(xiàng)目就是參數(shù),或者方法獲取            sendMessage(session,producer);            session.commit();        }catch (Exception e){            e.printStackTrace();        }finally {            try {                if(null != connection)                    connection.close();            }catch (Throwable ignore){}        }    }    public static void sendMessage(Session session, MessageProducer producer) throws Exception{            for (int i = 1; i <= 100000; i++){            TextMessage message = session.createTextMessage("今日天氣asda" + i);//發(fā)送消息到目的地            System.out.println("發(fā)送:"+message.getText());            producer.send(message);        }    }}

接收端程序

import org.apache.activemq.ActiveMQConnection;import org.apache.activemq.ActiveMQConnectionFactory;import javax.jms.*;public class revice {    public static void main(String[] args) {        ConnectionFactory connectionFactory;        Connection connection = null;        Session session;        Destination destination;        //接收者-消費(fèi)者        MessageConsumer messageConsumer;        connectionFactory = new ActiveMQConnectionFactory(                ActiveMQConnectionFactory.DEFAULT_USER,                ActiveMQConnectionFactory.DEFAULT_PASSWORD, "tcp://www.www.fjxmxtpower.cn:61616");                        try{            connection = connectionFactory.createConnection();            connection.start();            session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);            destination = session.createQueue("test");            messageConsumer = session.createConsumer(destination);            while(true){                TextMessage message = (TextMessage) messageConsumer.receive(1000);                                if(null != message){                    System.out.println("收到:"+message.getText());                }else{                    break;                }                message.acknowledge();            }        }catch(Exception ex){            ex.printStackTrace();        }finally{            try{                if(null != connection){                    connection.close();                }            }catch(Throwable ig){            }        }    }}              
              

active MQ

相關(guān)案例查看更多

主站蜘蛛池模板: 武安市| 徐闻县| 海阳市| 临泽县| 巴马| 无极县| 浑源县| 西盟| 北辰区| 岐山县| 唐河县| 三河市| 梁河县| 石家庄市| 洪湖市| 阆中市| 金湖县| 和田县| 平利县| 纳雍县| 扬州市| 邳州市| 水城县| 山阴县| 周口市| 天气| 扶余县| 青神县| 论坛| 牙克石市| 无棣县| 丹江口市| 息烽县| 神农架林区| 广丰县| 博罗县| 肥城市| 吴堡县| 鄯善县| 本溪| 霍林郭勒市|