public class JmsProduce { public static final String ACTIVEMQ_URL = "tcp://192.168.xx.xxx:61616"; public static void main(String[] args) throws Exception{ //创建activemq连接工厂 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ACTIVEMQ_URL); //获得连接 Connection connection = factory.createConnection(); //打开连接 connection.start(); //创建session Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); //创建目的地对象 Destination queue = session.createQueue("queue01"); //创建生产者 MessageProducer producer = session.createProducer(queue); //创建文本并发送 for(int i=0;i<3;i++){ TextMessage message = session.createTextMessage("message" + i); producer.send(message); } //关闭资源 producer.close(); session.close(); connection.close(); } }
这里说下是Number of Consumers,这个指的是在线等着的消费者,如果消费者断开与activemq的连接了,则该消费者不算在其内