View Full Version : Spring & MDBs
sellerjd
Apr 18th, 2006, 09:19 AM
I'm attempting to implement an asynchronous messaging client/server solution using Spring. One of the requests is to solve this using MDBs (Message Driven Beans). I've found very little support for Spring/MDB configurations. What are people's thoughts/experiences with using these two technologies together?
I am really looking for good examples on how these two interact, how they are configured to work together, etc. Fyi, our solution currently has JBoss as the app server.
conne67
Apr 18th, 2006, 09:43 AM
I'm attempting to implement an asynchronous messaging client/server solution using Spring. One of the requests is to solve this using MDBs (Message Driven Beans). I've found very little support for Spring/MDB configurations. What are people's thoughts/experiences with using these two technologies together?
I am really looking for good examples on how these two interact, how they are configured to work together, etc. Fyi, our solution currently has JBoss as the app server.
sellerjd,
try and have a look at the ActiveMq site (http://www.activemq.org/Spring+Support)
regards
conne67
sellerjd
Apr 19th, 2006, 08:48 AM
Are you saying that Spring and MDBs shouldn't/can't be used together?
I found the JBossSpringIntegration written by Justin, on JBoss.com and I seem to have my MDB depolyed via this approach, but it is not listening to the queue correctly. It appears that upon deployment, the public constructor of my MDB is called, however the ejbCreate method is not. It is acting as if my MDB is simply a bean or EJB, not a message driven bean.
wpoitras
Apr 19th, 2006, 10:25 AM
I use Spring with MDBs on Weblogic 8.1, and I believe I got it working on JBoss 4.0 (it was a while ago). I create a subclass of AbstractJmsMessageDrivenBean and look up the listener in the onEjbCreate method, and invoke it in the onMessage method.
My biggest source of issues using MDBs is figuring out whether or not the application context loaded right. If it doesn't your onEjbCreate gets a runtime exception, and the bean get destroyed by the container. Turning on extra logging helps for me. You might consider using MockEJB to help unit test your MDB to make sure it can initialize properly.
sellerjd
Apr 19th, 2006, 10:50 AM
Bill,
Thanks for the response. Looking into it more...
-Jay
sellerjd
Apr 19th, 2006, 11:16 AM
Ok, so I understand a bit more now. I deploy my MDB that extends AbstractJmsMessageDrivenBean and Spring takes care of most things behind the scenes for me (getting context etc).
Where do I tell Spring which files to load (Spring context files)? Right now it's just the jboss-spring.xml. Not sure how to load the rest but I don't think I want to do it in the bean, I want it loaded once for the whole app server.
wpoitras
Apr 19th, 2006, 11:44 AM
There are two basic ways you can specify which Spring files to load:
- Specify a list in ejb/BeanFactoryPath env-entry in your deployment descriptor.
- Use a SingletonBeanFactoryLocator. I believe there are examples in the forum or the reference manual which talk about how to tell an EJB to use this instead of the default method (ejb/BeanFactoryPath)
To load it only once per server, you'd want to use the SingletonBeanFactoryLocator method.
donski
May 3rd, 2006, 08:12 PM
We are using Spring configured MDBs with Weblogic 8.1 for our project. I followed the approach outlined in http://dev2dev.bea.com/pub/a/2006/01/custom-mdb-processing.html?page=1. It's Weblogic specific but the general approach should be applicable for JBoss. We didn't implement any of the duplicate detection or QOS from the example.
I set the ejb/BeanFactoryPath in my ejb-jar.xml which picks up the applicationContext.xml files from any of the included jars in my EAR:
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>SimpleMdb</ejb-name>
<ejb-class>my.mdb.SimpleMdb</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>classpath*:applicationContext.xml</env-entry-value>
</env-entry>
</message-driven>
</enterprise-beans>
</ejb-jar>
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.