I am using activemq 4.1.1 on JDK6 with Tomcat 5.5.x.

I have a couple of webapp contexts in a servlet container that use activemq 
broker.
I have been using an external broker but would like to embed the broker in the
servlet container. I have the following questions.

1) Assume I have webapps A and B. Is it necessary that only one of the two 
webapps
   assume the responsibility of starting the broker? I mean, I would like to 
embed the
  starting of the broker in a jarfile that is shared by both the webapps. Its 
hence easy for me
  to keep the jarfile agnostic to which webapp its operating in and execute the 
broker start code
  at context startup.

  Stated simply, would this sequence cause two different brokers to attempt to 
start?
Should I build mechanisms to make sure the broker.start() is executed only once?

     Webapp A:
            context load { // Time t
                 Broker broker = new broker("tcp://localhost:61616"); 
//pseudocode
                 broker.start();
            }

        Webapp B:
            context load { // Time t + 5
                 Broker broker = new broker("tcp://localhost:61616"); 
//pseudocode
                 broker.start();
            }
                 
2) Assume webapp A starts the broker. Also, let's say Class X is defined in a 
jarfile
  common to both the webapps.

   Would this cause class cast exception if webapp B received an instance of 
class X
   from the broker? (since I assume the broker would use the webapp A 
classloader
   to load class X)?

   If so how do I avoid this class loading issue? Do I need to place the 
activemq jarfiles
   as well as the application jarfiles which contains classes of the messages 
dispatched
   over activemq to be in a shared system classpath common to both the webapp 
contexts?

3) In a setup such as this where multiple webapps share the same embedded 
broker,
   is it mandatory that they use an external broker?
    
    What are the other gotchas in using the embedded broker in this fashion?

Regards

/U

Reply via email to