標籤:commit XML pil 4.0 建立 while gpo on() alt
訊息佇列activeMq, 節省回應時間,解決了第三方回應時間長的問題讓其他客戶可以繼續訪問,
安裝activeMq
apache-activemq-5.14.0-bin\apache-activemq-5.14.0\bin\win64\activeMq.bat
建立一個maven java project
在瀏覽器中訪問路徑 http://localhost:8161/ 登入名稱admin 密碼為admin
1.pom.xml檔案
<dependencies> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.14.0</version></dependency> </dependencies> <build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>1.7</source><target>1.7</target></configuration></plugin></plugins></build>
生產任務
public static void main(String[] args) throws JMSException {//串連工廠ConnectionFactory factory = new ActiveMQConnectionFactory();//擷取一個串連Connection connection = factory.createConnection();//建立會話Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);//建立隊列化話題對象Queue queue = session.createQueue("hello");MessageProducer producer = session.createProducer(queue);for (int i = 0; i < 10; i++) {producer.send(session.createTextMessage("ActiveMQ"+i));}session.commit();}
產生了十條任務
消費(處理業務)
public static void main(String[] args) throws Exception {//串連工廠ConnectionFactory factory = new ActiveMQConnectionFactory();//擷取一個串連Connection connection = factory.createConnection();connection.start();//建立會話Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//建立隊列化話題對象Queue queue = session.createQueue("hello");MessageConsumer producer = session.createConsumer(queue);while(true){//接收訊息TextMessage receive = (TextMessage) producer.receive();if(receive!=null){System.out.println(receive.getText());}}}
activeMq之hello(java)