1 18 package org.apache.activemq.broker; 19 20 import org.apache.activemq.ActiveMQConnectionFactory; 21 import org.apache.activemq.broker.jmx.ManagementContext; 22 import org.apache.activemq.command.ActiveMQQueue; 23 import org.apache.activemq.demo.DefaultQueueSender; 24 25 import javax.jms.Connection ; 26 import javax.jms.MessageConsumer ; 27 import javax.jms.Session ; 28 29 35 public class Main { 36 protected static boolean createConsumers = false; 37 38 41 public static void main(String [] args) { 42 String brokerURI = "broker:(tcp://localhost:61616,stomp://localhost:61613)?persistent=false&useJmx=true"; 43 if (args.length > 0) { 44 brokerURI = args[0]; 45 } 46 try { 47 BrokerService broker = new BrokerService(); 51 broker.setPersistent(false); 52 53 ManagementContext managementContext = broker.getManagementContext(); 55 managementContext.setFindTigerMbeanServer(true); 56 managementContext.setUseMBeanServer(true); 57 managementContext.setCreateConnector(false); 58 59 broker.setUseJmx(true); 60 broker.addConnector("tcp://localhost:61616"); 62 broker.addConnector("stomp://localhost:61613"); 63 broker.start(); 64 65 66 DefaultQueueSender.main(new String []{"Prices.Equity.IBM"}); 68 DefaultQueueSender.main(new String []{"Prices.Equity.MSFT"}); 69 70 if (createConsumers) { 72 Connection connection = new ActiveMQConnectionFactory().createConnection(); 73 connection.start(); 74 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 75 MessageConsumer consumer1 = session.createConsumer(new ActiveMQQueue("Orders.IBM")); 76 MessageConsumer consumer2 = session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100"); 77 Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 78 MessageConsumer consumer3 = session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200"); 79 } 80 else { 81 broker.waitUntilStopped(); 83 } 84 } 85 catch (Exception e) { 86 System.out.println("Failed: " + e); 87 e.printStackTrace(); 88 } 89 } 90 } 91 | Popular Tags |