标签:注意 数据 完全 j2ee 删除 tin inter sleep exception
<dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-all</artifactId> <version>5.15.9</version> </dependency> <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>4.13</version> </dependency>
package com.xuweiwei; import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.*; public class QueueSender { public static void main(String[] args) throws JMSException, InterruptedException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://192.168.78.50:61616"); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("xuweiwei-queue"); MessageProducer producer = session.createProducer(destination); for (int i = 0; i < 10; i++) { TextMessage textMessage = session.createTextMessage("许威威就是好啊" + i); Thread.sleep(1000); //通过消费生产者发出消息 producer.send(textMessage); } session.commit(); session.close(); connection.close(); } }
package com.xuweiwei; import org.apache.activemq.ActiveMQConnectionFactory; import javax.jms.*; public class QueueReceiver { public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://192.168.78.50:61616"); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue("xuweiwei-queue"); MessageConsumer consumer = session.createConsumer(destination); for (int i = 0; i < 10; i++) { TextMessage textMessage = (TextMessage) consumer.receive(); session.commit(); System.out.println("消费了" + textMessage.getText()); } session.close(); connection.close(); } }
标签:注意 数据 完全 j2ee 删除 tin inter sleep exception
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/10887991.html