2008-07-09

Different MessageBrokerServlet in the same EAR

If you work with LCDS or BlazeDS and are about to configure a second web application inside the same EAR, then you might see an error like this when the application starts up:

javax.servlet.UnavailableException: MessageBroker already defined from MessageBrokerServlet with init parameter messageBrokerId = '__default__'

This is because the declaration of both the MessageBroker servlets in both web.xml files looks like so:

<servlet>
<servlet-name>MessageBrokerServlet</servlet-name>
<display-name>MessageBrokerServlet</display-name>
<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
<init-param>
<param-name>services.configuration.file</param-name>
<param-value>/WEB-INF/flex/services-config.xml</param-value>
</init-param>
<init-param>
<param-name>flex.write.path</param-name>
<param-value>/WEB-INF/flex</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>


The above declaration is the default, and when both servlets are initialized, both are given a default identifier of '__default__'. Thus when a second web application in the EAR is initialized, it fails with the above error. They must have different identifiers and you do this by specifying an additional parameter in the declaration of the servlets in each respective web.xml. The declaration of the identifier should be like so:

<init-param>
<param-name>messageBrokerId</param-name>
<param-value>55</param-value>
</init-param>

So now one of MessageBroker servlet's will have an identifier of '55'. Add the same parameter for the other servlet in the web.xml file of the other web application, with a different identifer and both web applications should operate properly.

3 comments:

Anonymous said...

Thanks, this helped a lot.

Anonymous said...

Thank you, that was just what i was looking for

Anonymous said...

This was a very useful post and gave us a hint to resolve the issue. I have one question though. assuming I add the suggested key-value pair in just one of the web.xml files. should this still work? in other words one message broker servlet would be called "MBS" and I leave the one in the other war file with __default__ - further to this. how can I ensure that the instance called MBS is processing the messages in first war file?