如下的內(nèi)容是關(guān)于Java調(diào)用ActiveMQ簡單范例的內(nèi)容,應(yīng)該能對大伙有所用。
員工經(jīng)過長期磨合與沉淀,具備了協(xié)作精神,得以通過團隊的力量開發(fā)出優(yōu)質(zhì)的產(chǎn)品。成都創(chuàng)新互聯(lián)堅持“專注、創(chuàng)新、易用”的產(chǎn)品理念,因為“專注所以專業(yè)、創(chuàng)新互聯(lián)網(wǎng)站所以易用所以簡單”。公司專注于為企業(yè)提供做網(wǎng)站、網(wǎng)站制作、微信公眾號開發(fā)、電商網(wǎng)站開發(fā),小程序設(shè)計,軟件按需網(wǎng)站制作等一站式互聯(lián)網(wǎng)企業(yè)服務(wù)。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("消息已經(jīng)發(fā)送。。。。");
message.clearProperties();
session.close();
connection.stop();
connection.close();
System.out.println("關(guān)閉資源。。。。");
} 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("關(guān)閉資源。。。。");
} catch (JMSException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
PropertyConfigurator.configure("c:\log4j.properties");
PTP_receive receive=new PTP_receive();
receive.receive();
}
}
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。