This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Websphere and the fly likes JMS topic listener without using MDBs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "JMS topic listener without using MDBs" Watch "JMS topic listener without using MDBs" New topic
Author

JMS topic listener without using MDBs

Akash Mohapatra
Greenhorn

Joined: Aug 20, 2007
Posts: 17
Hi,

How can I create JMS topic listeners in WAS without using Message Driven Beans ?

Thanks in advance.


SCJP 6.0, SCWCD 1.5
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

There's no need to use MDBs. Just using the standard messaging APIs to listen to the topic.

Have you tried any of the standard APIs?

Setting up JMS in WebSphere

-Cameron McKenzie
Akash Mohapatra
Greenhorn

Joined: Aug 20, 2007
Posts: 17
Appreciate the quick response Cameron.

I've tried out the standard JMS APIs but get an exception when trying to register a message listener on WAS.
The trace says:


As I understand now from here, it is not possible to run an implementor of MessageListener in a J2EE container. The article suggests to use MDBs for this purpose, but I do not want to use any EJB components unless there is no other way out.

So, is there a non-MDB way of registering message listeners in Websphere Application Server?

Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 112
i would like to join in on this question, we have an even more severe problem becouse this is not our code, but rather Ehcache jms replication system. (so we cannot change this)

is there anyway to get around this?
victor regpala
Greenhorn

Joined: Dec 10, 2008
Posts: 5
I was in a simillar situation a couple of weeks back. In my case it was a choice of using MDBs or using a Message Listener Container. Going the Spring route is quite easy you just need to define a Message Listener Container and inject your listener. Something like this:

<bean id="messageListener" class="jms.client.SampleMessageListener"></bean>

<bean id="listener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory">
<ref bean="jmsConnectionFactory" />
</property>
<property name="destination">
<ref bean="destination" />
</property>
<property name="messageListener">
<ref bean="messageListener" />
</property>
</bean>

Spring should handle everything for you.

After considering the pros and cons of both, i ended up using MDBs. hehe
Elhanan Maayan
Ranch Hand

Joined: May 04, 2009
Posts: 112
and in the case of ehcache??
Akash Mohapatra
Greenhorn

Joined: Aug 20, 2007
Posts: 17
Here is how I think we can simulate JMS topic listeners in WAS without using MDBs :

1. Using the com.ibm.websphere.asynchbeans package, we can create AlarmManager and AlarmListener instances. These AlarmListeners are basically configured to be fired in certain intervals of time. Though, using these classes ties us to the WAS runtime, this is the most appropriate way of spawing threads from inside the thread-managed WAS environment.

2. Synchronous JMS receive calls like Subscriber.receive() can be used from inside the "fired" method of these AlarmListeners inorder to listen for messages on desired topics.

In other words - we spawn a thread which which keeps listening on topics using synchronous receive APIs.

It's highly probable that Spring too takes a similar approach.

I am not sure about ehcache - but the same can be done there too.

Thanks


Akash Mohapatra
Greenhorn

Joined: Aug 20, 2007
Posts: 17
victor regpala wrote:I was in a simillar situation a couple of weeks back. In my case it was a choice of using MDBs or using a Message Listener Container. Going the Spring route is quite easy you just need to define a Message Listener Container and inject your listener. Something like this:

<bean id="messageListener" class="jms.client.SampleMessageListener"></bean>

<bean id="listener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory">
<ref bean="jmsConnectionFactory" />
</property>
<property name="destination">
<ref bean="destination" />
</property>
<property name="messageListener">
<ref bean="messageListener" />
</property>
</bean>

Spring should handle everything for you.

After considering the pros and cons of both, i ended up using MDBs. hehe


Can you please elaborate on the above pros and cons ?

Thanks
Levent Tokmak
Greenhorn

Joined: Sep 15, 2009
Posts: 1
Hi,
i would like to join in on this question too, i have same problem with oscache 2.3.2 (WebSphere 6.1).

[14.09.2009 14:39:17:414 EEST] 0000003d JMSBroadcasti I com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener initialize Starting JMS clustering (node name=node4, topic=OSCacheTopic, topic factory=OSCacheTopicFactory)
[14.09.2009 14:39:17:426 EEST] 0000003d AbstractCache E com.opensymphony.oscache.base.AbstractCacheAdministrator configureStandardListeners Could not initialize listener 'com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener'. Listener ignored.
com.opensymphony.oscache.base.InitializationException: Initialization of the JMSBroadcastingListener failed: javax.jms.IllegalStateException: CWSIA0084E: The method MessageConsumer.setMessageListener is not permitted in this container.
at com.opensymphony.oscache.plugins.clustersupport.JMSBroadcastingListener.initialize(JMSBroadcastingListener.java:144)
at com.opensymphony.oscache.base.AbstractCacheAdministrator.configureStandardListeners(AbstractCacheAdministrator.java:328)
at com.opensymphony.oscache.general.GeneralCacheAdministrator.createCache(GeneralCacheAdministrator.java:305)
at com.opensymphony.oscache.general.GeneralCacheAdministrator.<init>(GeneralCacheAdministrator.java:99)

is this problem related with topic configurations? How can i resolve this without changing oscache code?

Thanks...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMS topic listener without using MDBs
 
Similar Threads
how to poll a jms queue or topic for message using asynchronous communication
How does JMS do pulling?
Communication between JMS topics in different JMS servers
Rationale for Message Driven Beans
asynchronous java