You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by Jiang <zj...@163.com> on 2007/05/16 04:55:25 UTC

How to create BrokerService

I find BrokerFactory can create Broker. The method is createBroker(URI). If I
start one ActiveMQ Server on localhost and in Activemq.xml  open 
       <transportConnector name="openwire" uri="tcp://localhost:61616"
discoveryUri="multicast://default"/>
       <transportConnector name="ssl"     uri="ssl://localhost:61617"/>
       <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
    <managementContext>
       <managementContext connectorPort="1099"
jmxDomainName="org.apache.activemq"/>
    </managementContext>
Then BrokerService service = BrokerFactory.createBroker(new URI("xxxxx"));
here URI("xxxxx") what should I specific xxxxx  to connect to the ActiveMQ
server above?(What I mean is whether I can use createBroker to connect to
the Activemq server . Then I can get information about the server and admin
the server )

-- 
View this message in context: http://www.nabble.com/How-to-create-BrokerService-tf3762284s2354.html#a10634843
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Re: How to create BrokerService

Posted by Jiang <zj...@163.com>.
bsnyder , thanks a lot . I see what you mean. 
I still have some questions need your help .
First question: After I create topic "Hello" in the broker use the code you
shown , I can see it in the jconsole. But when I use client code to find the
topic (use JNDI lookup, code below:)
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
env.put(Context.PROVIDER_URL, "tcp://serverip:61616");
Context ctx = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory)
ctx.lookup("ConnectionFactory"); //it will success
Destination des = (Destination)ctx.lookup("Hello");  //it throw exception
about name cannot be found
Maybe I need do something else about JNDI ???
Second question: I use normal code as ConnectionFactory / Connection/
Session/ Destination , just as show below: 
ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory("admin","admin","tcp://serverip:61616");
Connection connection = (Connection)factory.createConnection();
Session session = connection.createSession(false, 0);
Topic topic = session.createTopic("Hello");
MessageProducer producer = session.createProducer(topic);
I can see from jconsole, there are 3 items added in the Topic directory.
ActiveMQ.Advisory.Connection
ActiveMQ.Advisory.Producer.Topic.Hello
ActiveMQ.Advisory.Topic
But if I use jmx code . It will just add one item to the Topic directory .
Hello
After I add Hello to broker use JMX code after broker starts .I f I run
ActiveMQConnectionFactory factory = new
ActiveMQConnectionFactory("admin","admin","tcp://serverip:61616");
Connection connection = (Connection)factory.createConnection();
Session session = connection.createSession(false, 0);
Topic topic = session.createTopic("Hello");
MessageProducer producer = session.createProducer(topic);
Then other 3 item still be added to the Topic directory(there will be 4
items below Topic directory). I was confused about : Hello /
ActiveMQ.Advisory.Producer.Topic.Hello   , are they different ??? If JNDI
can find the Hello added use JMX ,then topic with name "Hello" stands for
which one ???( I think in client code , maybe we will just use Hello for
these 2 topics' name , do I wrong ?)
Any help is thanks.

bsnyder wrote:
> 
> On 5/16/07, Jiang <zj...@163.com> wrote:
>>
>> bsnyder thanks a lot .The example you shown works well.  But I still have
>> a
>> question: In ActiveMQ , there is a broker.jmx package , in this package
>> there are a lot of classes such as BrokerView/QueryView and so on. I
>> think
>> if I use these classes many things will be easiyer. For example
>> DestinationView class , it has many method to use .But  its constructor
>> has
>> a ManagedRegionBroker , I don't no how to create one ManagedRegionBroker
>> object(Its constructor is so  complex , it need BrokerService and so on)
>> . I
>> do wonder whether I can use these classes to meet the need I mentioned
>> before(addTopic/removeTopic ...).
>>
>> public DestinationView(ManagedRegionBroker broker, Destination
>> destination){
>>         this.broker = broker;
>>         this.destination=destination;
>>     }
> 
> The View objects you mention are part of the ActiveMQ internals and
> are the actual MBeans that are get registered with the MBeanServer for
> various items internal to the ActiveMQ core architecture. These
> objects are not public JMX management APIs for ActiveMQ. The example
> that I provided demonstrates the use of the MBeanServerConnection to
> query for MBeans and to invoke methods. This is exactly what you
> should be using to mange ActiveMQ via JMX.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> Apache Geronimo - http://geronimo.apache.org/
> Apache ActiveMQ - http://activemq.org/
> Apache ServiceMix - http://servicemix.org/
> Castor - http://castor.org/
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-create-BrokerService-tf3762284s2354.html#a10658978
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Re: How to create BrokerService

Posted by Bruce Snyder <br...@gmail.com>.
On 5/16/07, Jiang <zj...@163.com> wrote:
>
> bsnyder thanks a lot .The example you shown works well.  But I still have a
> question: In ActiveMQ , there is a broker.jmx package , in this package
> there are a lot of classes such as BrokerView/QueryView and so on. I think
> if I use these classes many things will be easiyer. For example
> DestinationView class , it has many method to use .But  its constructor has
> a ManagedRegionBroker , I don't no how to create one ManagedRegionBroker
> object(Its constructor is so  complex , it need BrokerService and so on) . I
> do wonder whether I can use these classes to meet the need I mentioned
> before(addTopic/removeTopic ...).
>
> public DestinationView(ManagedRegionBroker broker, Destination destination){
>         this.broker = broker;
>         this.destination=destination;
>     }

The View objects you mention are part of the ActiveMQ internals and
are the actual MBeans that are get registered with the MBeanServer for
various items internal to the ActiveMQ core architecture. These
objects are not public JMX management APIs for ActiveMQ. The example
that I provided demonstrates the use of the MBeanServerConnection to
query for MBeans and to invoke methods. This is exactly what you
should be using to mange ActiveMQ via JMX.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/

Re: How to create BrokerService

Posted by Jiang <zj...@163.com>.
bsnyder thanks a lot .The example you shown works well.  But I still have a
question: In ActiveMQ , there is a broker.jmx package , in this package
there are a lot of classes such as BrokerView/QueryView and so on. I think
if I use these classes many things will be easiyer. For example
DestinationView class , it has many method to use .But  its constructor has
a ManagedRegionBroker , I don't no how to create one ManagedRegionBroker
object(Its constructor is so  complex , it need BrokerService and so on) . I
do wonder whether I can use these classes to meet the need I mentioned
before(addTopic/removeTopic ...).

public DestinationView(ManagedRegionBroker broker, Destination destination){
        this.broker = broker;
        this.destination=destination;
    }


bsnyder wrote:
> 
> On 5/16/07, Jiang <zj...@163.com> wrote:
>>
>> bsnyder thanks a lot.
>> In fact I just want to admin ActiveMQ from remote admin tools(which
>> written
>> by myself). I want to add/remove destinations on that  MQ server .  From
>> my
>> opinion, I think I should first get a referece of the remote server ,then
>> I
>> can do some operations on the server through that ref ( What I do is not
>> create the broker really , In fact it has been created and run on the
>> server
>> when Activemq server starts.I just use it .Maybe what I think is wrong).
>> So
>> I connect to the broker at first step use the original code BrokerService
>> service = BrokerFactory.createBroker(new URI("xxxxx")); or maybe the code
>> you write for example , then I will use the code below:
>>      ActiveMQDestination[] destinations = service.getDestinations(); 
>> //to
>> get destinations list
>>      BrokerView brview = service.getAdminView();    //get the admin
>> BrokerView
>>      brview.addTopic("Hello");    //add Hello topic to the broker ---
>> Step 1
>>      brview.addTopic("World");  //add World topic to the broker---Step 2
>>      brview.removeTopic("Hello");  //remove Hello topic from the
>> broker---Step3
>>     brview.removeTopic("World");  //remove World topic from the
>> broker---Step 4
>> All the add/remove actions can been seen from the jconsole (after Step1 ,
>> we
>> can seen from jconsole that Hello Topic has been added. after Step2 we
>> can
>> seen World topic has been added. after Step3 Hello topic can been seen
>> removed. after Step4 just as Step3 )
>>
>> bsnyder what I say is right ? (Now the code I wirte above has not been
>> tested for lack of environment. I will test it late )
> 
> OK, I see what you need now. You need to use the methods exposed via
> JMX to achieve this task. I'm attaching a file that is an example of
> exactly this. Let me know if you have any questions.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> Apache Geronimo - http://geronimo.apache.org/
> Apache ActiveMQ - http://activemq.org/
> Apache ServiceMix - http://servicemix.org/
> Castor - http://castor.org/
> 
> package com.logicblaze.fuse;
> 
> import java.io.IOException;
> import java.net.MalformedURLException;
> import java.util.HashMap;
> import java.util.Iterator;
> import java.util.Map;
> import java.util.Set;
> import java.util.logging.Level;
> import java.util.logging.Logger;
> 
> import javax.management.AttributeNotFoundException;
> import javax.management.InstanceNotFoundException;
> import javax.management.IntrospectionException;
> import javax.management.MBeanAttributeInfo;
> import javax.management.MBeanException;
> import javax.management.MBeanInfo;
> import javax.management.MBeanServerConnection;
> import javax.management.MalformedObjectNameException;
> import javax.management.ObjectInstance;
> import javax.management.ObjectName;
> import javax.management.Query;
> import javax.management.QueryExp;
> import javax.management.ReflectionException;
> import javax.management.remote.JMXConnector;
> import javax.management.remote.JMXConnectorFactory;
> import javax.management.remote.JMXServiceURL;
> 
> import junit.framework.Test;
> import junit.framework.TestCase;
> import junit.framework.TestSuite;
> 
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> 
> /**
>  * Programmatic JMX example
>  * 
>  * Instructions for running this code:
>  * <ol type="1">
>  * <li>Start up FUSE</li>
>  * <li>Execute the build for this test using the following command on the
> command line:
>  * <tt>$ mvn install </tt> </li>
>  * </ol>
>  */
> public class AMQJmxExampleTest extends TestCase {
>     private static final Log log =
> LogFactory.getLog(AMQJmxExampleTest.class);
> 
>     public String amqJmxUrl =
> "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
> 
>     /**
>      * Create the test case
>      * 
>      * @param testName name of the test case
>      */
>     public AMQJmxExampleTest(String testName) {
>         super(testName);
>     }
> 
>     /**
>      * @return the suite of tests being tested
>      */
>     public static Test suite() {
>         return new TestSuite(JmxExampleTest.class);
>     }
> 
>     public void testApp() {
>         MBeanServerConnection connection;
>         
>         String clientServiceName =
> "org.apache.activemq:ContainerName=ServiceMix,Type=SystemService,Name=ClientFactory";
>         
>         String topicName = "Boulder.Colorado";
>         
>         try {
>             // Acquire a connection to the MBean server
>             connection = connect();
>             
>             // How many MBeans are running? 
>             count(connection);
>             
>             // Query for a single MBean 
>             query(connection, clientServiceName);
>             
>             // Query all MBeans 
>             query(connection, "");
>             
>             // Check for the topic first 
>             Set mbeans = queryForTopic(connection, topicName);
>             
>             log.info("Located [" + mbeans.size() + "] MBeans");
>             
>             if(mbeans.size() > 0) {
>                 // Create a new topic on the broker
>                 createTopic(connection, topicName);
>             }
>             else {
>                 // Remove the topic from the broker and then create it
>                 removeTopic(connection, topicName);
>                 createTopic(connection, topicName);
>             }
>             
>             mbeans = queryForTopic(connection, topicName);
>             
>             log.info("Located [" + mbeans.size() + "] MBeans");
>             
>         } catch (IOException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>     }
>     
>     public MBeanServerConnection connect() 
>         throws IOException {
>         JMXConnector connector = null;
>         MBeanServerConnection connection = null;
> 
>         String username = "";
> 
>         String password = "";
> 
>         Map env = new HashMap();
>         String[] credentials = new String[] { username, password };
>         env.put(JMXConnector.CREDENTIALS, credentials);
> 
>         try {
>             connector = JMXConnectorFactory.newJMXConnector(new
> JMXServiceURL(amqJmxUrl), env);
>             connector.connect();
>             connection = connector.getMBeanServerConnection();
>         } catch (MalformedURLException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (IOException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>         
>         return connection; 
>     }
>     
>     public void count(MBeanServerConnection conn)
>         throws IOException {
>         int numberOfMBeans = conn.getMBeanCount().intValue();
>         log.info("Number of MBeans currently running: " + numberOfMBeans);
>     }
>     
>     public void query(MBeanServerConnection conn, String query)
>         throws IOException {
>         if (conn != null && query != null) {
>             listMBeans(conn, query);
>         } else if (conn != null && query.equals("")) {
>             listAllMBeanNames(conn);
>         } else {
>             log.fatal("Unable to connect to ServiceMix");
>         }
>     }
>     
>     public void listMBeans(MBeanServerConnection conn, String query) 
>         throws IOException {
>         ObjectName name;
>         Set names = null; 
>         try {
>             name = new ObjectName(query);
>             names = conn.queryMBeans(name, name);
>         } catch (MalformedObjectNameException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (NullPointerException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>         
>         for(Iterator iter = names.iterator(); iter.hasNext(); ) {
>             ObjectInstance obj = (ObjectInstance) iter.next();
>             log.info("+ " + obj.getClassName());
>         }
>     }
>     
>     public void listAllMBeanNames(MBeanServerConnection conn)
>         throws IOException {
>         Set names = getAllMBeanNames(conn);
> 
>         for (Iterator iter = names.iterator(); iter.hasNext();) {
>             ObjectName objName = (ObjectName) iter.next();
>             log.info("+ " + objName);
>         }
>     }
>     
>     public void listMBeanAttrs(MBeanServerConnection conn, String query) 
>         throws IOException {
>         ObjectName objName = null;
>         try {
>             objName = new ObjectName(query);
>             log.info("+ " + objName.getCanonicalName()); 
>             
>             MBeanInfo info = getMBeanInfo(conn, objName); 
>             MBeanAttributeInfo[] attrs = info.getAttributes(); 
>             
>             for(int i = 0; i < attrs.length; ++i) {
>                 Object obj = conn.getAttribute(objName,
> attrs[i].getName());
>                 log.info("  - " + attrs[i].getName() + obj);
>             }
>         } catch (MalformedObjectNameException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (NullPointerException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (AttributeNotFoundException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (InstanceNotFoundException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (MBeanException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (ReflectionException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>     }
>     
>     public void createTopic(MBeanServerConnection conn, String topicName)
>         throws IOException {
>         String brokerNameQuery =
> "org.apache.activemq:BrokerName=localhost,Type=Broker";
>         String addTopicOperationName = "addTopic";
>         Object[] params = { topicName };
>         String[] sig = { "java.lang.String" };
>         
>         doTopicCrud(conn, topicName, brokerNameQuery,
> addTopicOperationName, params, sig, "creat");
>     }
>     
>     private void removeTopic(MBeanServerConnection conn, String topicName) 
>         throws IOException {
>         String brokerNameQuery =
> "org.apache.activemq:BrokerName=localhost,Type=Broker";
>         String removeTopicOperationName = "removeTopic";
>         Object[] params = { topicName };
>         String[] sig = { "java.lang.String" };
>         
>         doTopicCrud(conn, topicName, brokerNameQuery,
> removeTopicOperationName, params, sig, "remov");
>     }
> 
>     private void doTopicCrud(MBeanServerConnection conn, String topicName, 
>             String brokerNameQuery, String operationName, Object[] params,
> String[] sig, String verb) 
>         throws IOException {
>         ObjectName brokerObjName;
>         
>         try {
>                 log.info( verb + "ing new topic: [" + topicName + "]");
>                 brokerObjName = new ObjectName(brokerNameQuery); 
>                 conn.invoke(brokerObjName, operationName, params, sig);
>                 log.info("Topic [" + topicName + "] has been " + verb +
> "ed");
>         } catch (MalformedObjectNameException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (NullPointerException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (InstanceNotFoundException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (MBeanException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (ReflectionException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>     }
>     
>     
> 
>     private void printMBeans(String topicName, Set mbeans) {
>         if (!mbeans.isEmpty()) {
>             for (Iterator iter = mbeans.iterator(); iter.hasNext();) {
>                 ObjectInstance mbean = (ObjectInstance) iter.next();
>                 log.info("+ " + mbean.getClassName());
>             }
>         } 
>         else {
>             log.info("Unable to locate MBean for " + topicName);
>         }
>     }
> 
>     public Set queryForTopic(MBeanServerConnection conn, String topicName) 
>         throws IOException {
>         // Was the topic created?  
>         String topicsQuery =
> "org.apache.activemq:BrokerName=localhost,Type=Topic,*";
>         // listMBeans(conn, topicsQuery);
> 
>         // Use JMX query expressions
>         QueryExp queryExp = Query.eq(Query.attr("name"),
> Query.value(topicName)); 
> 
>         ObjectName objName;
>         Set mbeans = null; 
>         try {
>             objName = new ObjectName(topicsQuery);
>             log.info("Querying for " + topicName);
>             mbeans = conn.queryMBeans(objName, queryExp);       
>         } catch (MalformedObjectNameException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         } catch (NullPointerException e) {
>             // TODO Auto-generated catch block
>             e.printStackTrace();
>         }
>         
>         return mbeans;
>     }
> 
>     public void listAllMBeanAttrs(MBeanServerConnection conn, Set names) 
>         throws IOException {
> 
>         for (Iterator iter = names.iterator(); iter.hasNext();) {
>             ObjectName objName = (ObjectName) iter.next();
>             log.info("+ " + objName);
> 
>             MBeanInfo info = getMBeanInfo(conn, objName);
>             
>             MBeanAttributeInfo[] attrs = info.getAttributes();
> 
>             if (attrs == null)
>                 continue;
> 
>             for (int i = 0; i < attrs.length; ++i) {
>                 try {
>                     Object obj = conn.getAttribute(objName,
> attrs[i].getName());
>                     log.info(" - " + attrs[i].getName() + " = " + obj);
>                 } catch (NullPointerException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 } catch (AttributeNotFoundException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 } catch (InstanceNotFoundException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 } catch (MBeanException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 } catch (ReflectionException e) {
>                     // TODO Auto-generated catch block
>                     e.printStackTrace();
>                 }
>             }
>         }
>     }
>     
>     public void query(MBeanServerConnection conn, QueryExp queryExp)
>         throws IOException {
>         log.info("Not yet implemented"); 
>     }
>     
>     // Private
> ----------------------------------------------------------------
> 
>     private MBeanInfo getMBeanInfo(MBeanServerConnection conn, ObjectName
> objName) 
>         throws IOException {
>         MBeanInfo info = null;
>         
>         try {
>             info = conn.getMBeanInfo((ObjectName) objName);
>         } catch (InstanceNotFoundException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         } catch (IntrospectionException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         } catch (ReflectionException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         }
>         
>         return info;
>     }
>     
>     private Set getAllMBeanNames(MBeanServerConnection conn)
>         throws IOException {
>         return conn.queryNames(null, null);
>     }
> }
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-create-BrokerService-tf3762284s2354.html#a10657563
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Re: How to create BrokerService

Posted by Bruce Snyder <br...@gmail.com>.
On 5/16/07, Jiang <zj...@163.com> wrote:
>
> bsnyder thanks a lot.
> In fact I just want to admin ActiveMQ from remote admin tools(which written
> by myself). I want to add/remove destinations on that  MQ server .  From my
> opinion, I think I should first get a referece of the remote server ,then I
> can do some operations on the server through that ref ( What I do is not
> create the broker really , In fact it has been created and run on the server
> when Activemq server starts.I just use it .Maybe what I think is wrong). So
> I connect to the broker at first step use the original code BrokerService
> service = BrokerFactory.createBroker(new URI("xxxxx")); or maybe the code
> you write for example , then I will use the code below:
>      ActiveMQDestination[] destinations = service.getDestinations();  //to
> get destinations list
>      BrokerView brview = service.getAdminView();    //get the admin
> BrokerView
>      brview.addTopic("Hello");    //add Hello topic to the broker --- Step 1
>      brview.addTopic("World");  //add World topic to the broker---Step 2
>      brview.removeTopic("Hello");  //remove Hello topic from the
> broker---Step3
>     brview.removeTopic("World");  //remove World topic from the
> broker---Step 4
> All the add/remove actions can been seen from the jconsole (after Step1 , we
> can seen from jconsole that Hello Topic has been added. after Step2 we can
> seen World topic has been added. after Step3 Hello topic can been seen
> removed. after Step4 just as Step3 )
>
> bsnyder what I say is right ? (Now the code I wirte above has not been
> tested for lack of environment. I will test it late )

OK, I see what you need now. You need to use the methods exposed via
JMX to achieve this task. I'm attaching a file that is an example of
exactly this. Let me know if you have any questions.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/

Re: How to create BrokerService

Posted by Jiang <zj...@163.com>.
bsnyder thanks a lot. 
In fact I just want to admin ActiveMQ from remote admin tools(which written
by myself). I want to add/remove destinations on that  MQ server .  From my
opinion, I think I should first get a referece of the remote server ,then I
can do some operations on the server through that ref ( What I do is not
create the broker really , In fact it has been created and run on the server
when Activemq server starts.I just use it .Maybe what I think is wrong). So
I connect to the broker at first step use the original code BrokerService
service = BrokerFactory.createBroker(new URI("xxxxx")); or maybe the code
you write for example , then I will use the code below:
     ActiveMQDestination[] destinations = service.getDestinations();  //to
get destinations list
     BrokerView brview = service.getAdminView();    //get the admin
BrokerView
     brview.addTopic("Hello");    //add Hello topic to the broker --- Step 1
     brview.addTopic("World");  //add World topic to the broker---Step 2
     brview.removeTopic("Hello");  //remove Hello topic from the
broker---Step3
    brview.removeTopic("World");  //remove World topic from the
broker---Step 4
All the add/remove actions can been seen from the jconsole (after Step1 , we
can seen from jconsole that Hello Topic has been added. after Step2 we can
seen World topic has been added. after Step3 Hello topic can been seen
removed. after Step4 just as Step3 )

bsnyder what I say is right ? (Now the code I wirte above has not been
tested for lack of environment. I will test it late )
Thanks.	  

bsnyder wrote:
> 
> On 5/15/07, Jiang <zj...@163.com> wrote:
>>
>> I find BrokerFactory can create Broker. The method is createBroker(URI).
>> If I
>> start one ActiveMQ Server on localhost and in Activemq.xml  open
>>        <transportConnector name="openwire" uri="tcp://localhost:61616"
>> discoveryUri="multicast://default"/>
>>        <transportConnector name="ssl"     uri="ssl://localhost:61617"/>
>>        <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
>>     <managementContext>
>>        <managementContext connectorPort="1099"
>> jmxDomainName="org.apache.activemq"/>
>>     </managementContext>
>> Then BrokerService service = BrokerFactory.createBroker(new
>> URI("xxxxx"));
>> here URI("xxxxx") what should I specific xxxxx  to connect to the
>> ActiveMQ
>> server above?(What I mean is whether I can use createBroker to connect to
>> the Activemq server . Then I can get information about the server and
>> admin
>> the server )
> 
> You can just use the URI for the transport connector you'd like the
> BrokerFactory to use from your configuration file. Below is an example
> of this:
> 
> BrokerService service = BrokerFactory.createBroker(new
> URI("tcp://localhost:61616"));
> 
> But I'm curious to know what exactly are you trying to do? If you're
> just trying to create a broker, it's much easier to create a
> BrokerService object and then just call getBroker() method to grab the
> actual Broker object (if you really need the Broker object - I'm
> willing to be you don't need it, but I could be wrong). Below is an
> example of this:
> 
> BrokerService brokerService = new BrokerService();
> brokerService.setUseJmx(true);
> brokerService.addConnector("tcp://localhost:61616");
> brokerService.start();
> 
> Another option is to use the BrokerFactoryBean and a standard
> activemq.xml configuration file. Below is an example of this:
> 
> BrokerFactoryBean factoryBean = new BrokerFactoryBean(new
> ClassPathResource("org/apache/servicemix/jms/activemq.xml"));
> factoryBean.afterPropertiesSet();
> Broker broker = bfb.getBroker();
> broker.start();
> 
> Hope this helps.
> 
> Bruce
> -- 
> perl -e 'print
> unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
> );'
> 
> Apache Geronimo - http://geronimo.apache.org/
> Apache ActiveMQ - http://activemq.org/
> Apache ServiceMix - http://servicemix.org/
> Castor - http://castor.org/
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-create-BrokerService-tf3762284s2354.html#a10635961
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.


Re: How to create BrokerService

Posted by Bruce Snyder <br...@gmail.com>.
On 5/15/07, Bruce Snyder <br...@gmail.com> wrote:
> On 5/15/07, Jiang <zj...@163.com> wrote:
> >
> > I find BrokerFactory can create Broker. The method is createBroker(URI). If I
> > start one ActiveMQ Server on localhost and in Activemq.xml  open
> >        <transportConnector name="openwire" uri="tcp://localhost:61616"
> > discoveryUri="multicast://default"/>
> >        <transportConnector name="ssl"     uri="ssl://localhost:61617"/>
> >        <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
> >     <managementContext>
> >        <managementContext connectorPort="1099"
> > jmxDomainName="org.apache.activemq"/>
> >     </managementContext>
> > Then BrokerService service = BrokerFactory.createBroker(new URI("xxxxx"));
> > here URI("xxxxx") what should I specific xxxxx  to connect to the ActiveMQ
> > server above?(What I mean is whether I can use createBroker to connect to
> > the Activemq server . Then I can get information about the server and admin
> > the server )
>
> You can just use the URI for the transport connector you'd like the
> BrokerFactory to use from your configuration file. Below is an example
> of this:
>
> BrokerService service = BrokerFactory.createBroker(new
> URI("tcp://localhost:61616"));
>
> But I'm curious to know what exactly are you trying to do? If you're
> just trying to create a broker, it's much easier to create a
> BrokerService object and then just call getBroker() method to grab the
> actual Broker object (if you really need the Broker object - I'm
> willing to be you don't need it, but I could be wrong). Below is an
> example of this:
>
> BrokerService brokerService = new BrokerService();
> brokerService.setUseJmx(true);
> brokerService.addConnector("tcp://localhost:61616");
> brokerService.start();
>
> Another option is to use the BrokerFactoryBean and a standard
> activemq.xml configuration file. Below is an example of this:
>
> BrokerFactoryBean factoryBean = new BrokerFactoryBean(new
> ClassPathResource("org/apache/servicemix/jms/activemq.xml"));
> factoryBean.afterPropertiesSet();
> Broker broker = bfb.getBroker();
> broker.start();
>
> Hope this helps.

By the way, your requests seem to be more appropriate for the ActiveMQ
user mailing list instead of the dev mailing list. More info on the
lists can be found here:

http://activemq.apache.org/mailing-lists.html

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/

Re: How to create BrokerService

Posted by Bruce Snyder <br...@gmail.com>.
On 5/15/07, Jiang <zj...@163.com> wrote:
>
> I find BrokerFactory can create Broker. The method is createBroker(URI). If I
> start one ActiveMQ Server on localhost and in Activemq.xml  open
>        <transportConnector name="openwire" uri="tcp://localhost:61616"
> discoveryUri="multicast://default"/>
>        <transportConnector name="ssl"     uri="ssl://localhost:61617"/>
>        <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
>     <managementContext>
>        <managementContext connectorPort="1099"
> jmxDomainName="org.apache.activemq"/>
>     </managementContext>
> Then BrokerService service = BrokerFactory.createBroker(new URI("xxxxx"));
> here URI("xxxxx") what should I specific xxxxx  to connect to the ActiveMQ
> server above?(What I mean is whether I can use createBroker to connect to
> the Activemq server . Then I can get information about the server and admin
> the server )

You can just use the URI for the transport connector you'd like the
BrokerFactory to use from your configuration file. Below is an example
of this:

BrokerService service = BrokerFactory.createBroker(new
URI("tcp://localhost:61616"));

But I'm curious to know what exactly are you trying to do? If you're
just trying to create a broker, it's much easier to create a
BrokerService object and then just call getBroker() method to grab the
actual Broker object (if you really need the Broker object - I'm
willing to be you don't need it, but I could be wrong). Below is an
example of this:

BrokerService brokerService = new BrokerService();
brokerService.setUseJmx(true);
brokerService.addConnector("tcp://localhost:61616");
brokerService.start();

Another option is to use the BrokerFactoryBean and a standard
activemq.xml configuration file. Below is an example of this:

BrokerFactoryBean factoryBean = new BrokerFactoryBean(new
ClassPathResource("org/apache/servicemix/jms/activemq.xml"));
factoryBean.afterPropertiesSet();
Broker broker = bfb.getBroker();
broker.start();

Hope this helps.

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/