ActiveMQ(一)
生活随笔
收集整理的這篇文章主要介紹了
ActiveMQ(一)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
一:傳統(tǒng)RPC中間件的缺點(diǎn):corba、dcom、RMI
二:面向消息的中間件Message Oriented Middleware ,MOM介紹
三:JMS簡介
四:activeMQ介紹
向中間件中添加數(shù)據(jù):
public class Sender {public static void main(String[] args) throws Exception {// 1創(chuàng)建連接工廠ConnectionFactory connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER, ActiveMQConnectionFactory.DEFAULT_PASSWORD,ActiveMQConnectionFactory.DEFAULT_BROKER_URL);// 2通過連接工廠創(chuàng)建連接,并開啟連接Connection connection = connectionFactory.createConnection();connection.start();// 3創(chuàng)建session回話1.是否啟動(dòng)事物,2.簽收模式Session session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);// 4創(chuàng)建目標(biāo)對(duì)象在p2p模式中目的地被稱為Queue,pb模式下被稱為TopicDestination destination = session.createQueue("queue1");// 5通過session創(chuàng)建生產(chǎn)者或消費(fèi)者M(jìn)essageproducer/MessageConsumerMessageProducer messageProvider = session.createProducer(destination);// 6設(shè)置持久化存儲(chǔ)特性,是否持久化存儲(chǔ)或者臨時(shí)存儲(chǔ)messageProvider.setDeliveryMode(DeliveryMode.NON_PERSISTENT);// 非持久化// 7創(chuàng)建數(shù)據(jù)對(duì)象,messageProvider發(fā)送該數(shù)據(jù),供消費(fèi)者使用for (int i = 0; i < 5; i++) {TextMessage textMessage = session.createTextMessage();textMessage.setText("我是消息內(nèi)容," + i);// 發(fā)送消息messageProvider.send(textMessage);}if (connection != null) {connection.close();}}獲取中間件中存放的數(shù)據(jù):
public class Sender {public static void main(String[] args) throws Exception {// 1創(chuàng)建連接工廠ConnectionFactory connectionFactory = new org.apache.activemq.ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_USER, ActiveMQConnectionFactory.DEFAULT_PASSWORD,ActiveMQConnectionFactory.DEFAULT_BROKER_URL);// 2通過連接工廠創(chuàng)建連接,并開啟連接Connection connection = connectionFactory.createConnection();connection.start();// 3創(chuàng)建session回話1.是否啟動(dòng)事物,2.簽收模式Session session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);// 4創(chuàng)建目標(biāo)對(duì)象在p2p模式中目的地被稱為Queue,pb模式下被稱為TopicDestination destination = session.createQueue("queue1");// 5通過session創(chuàng)建生產(chǎn)者或消費(fèi)者M(jìn)essageproducer/MessageConsumerMessageProducer messageProvider = session.createProducer(destination);// 6設(shè)置持久化存儲(chǔ)特性,是否持久化存儲(chǔ)或者臨時(shí)存儲(chǔ)messageProvider.setDeliveryMode(DeliveryMode.NON_PERSISTENT);// 非持久化// 7創(chuàng)建數(shù)據(jù)對(duì)象,messageProvider發(fā)送該數(shù)據(jù),供消費(fèi)者使用for (int i = 0; i < 5; i++) {TextMessage textMessage = session.createTextMessage();textMessage.setText("我是消息內(nèi)容," + i);// 發(fā)送消息messageProvider.send(textMessage);}if (connection != null) {connection.close();}}?
?
轉(zhuǎn)載于:https://my.oschina.net/2286252881/blog/854005
總結(jié)
以上是生活随笔為你收集整理的ActiveMQ(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中的一些算法
- 下一篇: JVM中的垃圾收集算法和Heap分区简记