KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > broker > Main


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 JavaDoc;
26 import javax.jms.MessageConsumer JavaDoc;
27 import javax.jms.Session JavaDoc;
28
29 /**
30  * A helper class which can be handy for running a broker in your IDE from the
31  * activemq-core module.
32  *
33  * @version $Revision: 512764 $
34  */

35 public class Main {
36     protected static boolean createConsumers = false;
37
38     /**
39      * @param args
40      */

41     public static void main(String JavaDoc[] args) {
42         String JavaDoc 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             // TODO - this seems to break interceptors for some reason
48
// BrokerService broker = BrokerFactory.createBroker(new
49
// URI(brokerURI));
50
BrokerService broker = new BrokerService();
51             broker.setPersistent(false);
52
53             // for running on Java 5 without mx4j
54
ManagementContext managementContext = broker.getManagementContext();
55             managementContext.setFindTigerMbeanServer(true);
56             managementContext.setUseMBeanServer(true);
57             managementContext.setCreateConnector(false);
58
59             broker.setUseJmx(true);
60             //broker.setPlugins(new BrokerPlugin[] { new ConnectionDotFilePlugin(), new UDPTraceBrokerPlugin() });
61
broker.addConnector("tcp://localhost:61616");
62             broker.addConnector("stomp://localhost:61613");
63             broker.start();
64
65
66             // lets publish some messages so that there is some stuff to browse
67
DefaultQueueSender.main(new String JavaDoc[]{"Prices.Equity.IBM"});
68             DefaultQueueSender.main(new String JavaDoc[]{"Prices.Equity.MSFT"});
69
70             // lets create a dummy couple of consumers
71
if (createConsumers) {
72                 Connection connection = new ActiveMQConnectionFactory().createConnection();
73                 connection.start();
74                 Session JavaDoc session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
75                 MessageConsumer JavaDoc consumer1 = session.createConsumer(new ActiveMQQueue("Orders.IBM"));
76                 MessageConsumer JavaDoc consumer2 = session.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 100");
77                 Session JavaDoc session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
78                 MessageConsumer JavaDoc consumer3 = session2.createConsumer(new ActiveMQQueue("Orders.MSFT"), "price > 200");
79             }
80             else {
81                 // Lets wait for the broker
82
broker.waitUntilStopped();
83             }
84         }
85         catch (Exception JavaDoc e) {
86             System.out.println("Failed: " + e);
87             e.printStackTrace();
88         }
89     }
90 }
91
Popular Tags