Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS topic listener without using MDBs

 
Akash Mohapatra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Thanks in advance.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and in the case of ehcache??
 
Akash Mohapatra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Marcel Friedmann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WebSphere supports to listen to queues and topics without mdbs.

Simply instanciate a TopicSubscriber (IBM class) or create a message listener.



Source:
http://www.devops-insight.com/2014/08/jms-in-websphere.html
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic