File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Websphere and the fly likes setMessageListener not permitted?? Why?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "setMessageListener not permitted?? Why??" Watch "setMessageListener not permitted?? Why??" New topic
Author

setMessageListener not permitted?? Why??

Juzar Roopawalla
Ranch Hand

Joined: Oct 30, 2001
Posts: 37
Hi,
I have a session bean which and some helper classes deployed in WAS 5.0. A couple of these helper classes implement MessageListener and I am doing a setMessageListener(this) in some method there. The session bean is not involved here.
I then deploy the ear which is smooth.
At runtime when those classes are initialized, I am getting an error saying 'setMessageListener not permitted'. Why is this happening?
I want to use pure asynchronous JMS and not use MDB's. Hence I have to use the same code!
Please let me know of this behaviour.
Regards,
Juzar.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Well, basically you can't do this. This is why they invented MDB's -- if we allowed you to do this then you would get into all sorts of transactional messes due to the fact that we couldn't tell what to do with the message receipt -- what transaction would it be a part of?
You're going to have to rewrite this as MDB's to be J2EE compliant.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
babu dinesh siddabathuni
Greenhorn

Joined: Jan 10, 2003
Posts: 2
kyle,
JMS listeners are supported by all other application servers (weblogic, borland and pramati). I understand that the J2ee specification does say that the setMessageListener API should not be supported. But JMS listeners work differently compared to MDBs.
1. It allows applications to listen to messages from JMS destinations (queues/topics) dynamically. MDBs force the application to know the destination it is listening to when the application is deployed to the container.
2. Messages are processed sequentially by a JMS listener. That is not the case with MDBs which spawn a new instance of the bean to process each message.
It is important for us to have the above mentioned functionality. Are you aware of any pattern that provides the above functionality using MDBS? Any help is greatly appreciated.
thanks,
Babu
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Yes, we know all that, and that is why we support message listeners OUTSIDE of the EJB container. Just do your message listening in the Servlet Container (outside of any transactional context, of course) and everything will be peachy.
Yes, other vendors are less strict about the J2EE specification than we are -- that doesn't mean that it's a problem with WebSphere -- we've encountered this kind of thing before, and the result of trying to "bend" the rules is that when the other vendors decide to finally live by the rules (usually because Sun includes a test for the stricter interpretation in the certification tests) then your code will break...
Kyle
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
BTW, another perfectly supported way to listen for messages in order of receipt and with dynamic selection of Queues or Topics is to listen synchronously with a MessageConsumer...
Kyle
babu dinesh siddabathuni
Greenhorn

Joined: Jan 10, 2003
Posts: 2
Kyle,
Thanks for the response. Our requirement is to listen to messages asynchronously.
thanks,
Babu
Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
Hi Kyle-
I'm trying to set up a messageListener in my servlet container (using WSAD5) and am now getting this error--according to your note earlier in this thread I should be able to do this, right?:
my code:
InitialContext ic = new InitialContext();
Context jndi = (Context)ic.lookup ("java:comp/env");
QueueConnectionFactory qcf = (QueueConnectionFactory)jndi.lookup(JNDI_KPC_QCF);
QueueConnection qConn = qcf.createQueueConnection();
QueueSession qSession = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);Queue q = (Queue)jndi.lookup(JNDI_KPC_REFRESH_QUEUE);
QueueReceiver qReceiver = qSession.createReceiver(q);
cacheRefreshListener = new CacheRefreshListener();
qReceiver.setMessageListener(cacheRefreshListener);
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Well, actually not. I've since found out from development that we no longer even allow setMessageListener() inside the Servlet container since it's been banned in J2EE 1.4 (yes, we're doing this in advance of full spec compliance).
Kyle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setMessageListener not permitted?? Why??