wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes MDB onMessage() not firing....Help needed please! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDB onMessage() not firing....Help needed please!" Watch "MDB onMessage() not firing....Help needed please!" New topic
Author

MDB onMessage() not firing....Help needed please!

clement valentine
Greenhorn

Joined: Apr 04, 2002
Posts: 19
Hello all,
Iam testing a simple application using MDB in Weblogic 8.1 but the onMessage() method never gets triggered when messages arrive on the queue!.
This is the gist of things : A session bean writes to the queue and an MDB should receive the message and do a database insert by calling the create method on a CMP.

These are my descriptors:

<ejb-jar>.xml
---------------------------------------------------------
.....
<message-driven>
<display-name>CustomerMDB</display-name>
<ejb-name>CustomerMDB</ejb-name>
<ejb-class>autofactory.CustomerMDBBean</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
</message-driven-destination>
</message-driven>
.......
-------------------------------------------------------------
weblogic-ejb-jar.xml

<weblogic-enterprise-bean>
<ejb-name>CustomerMDB</ejb-name>
<message-driven-descriptor>
<pool>
<max-beans-in-free-pool>20</max-beans-in-free-pool>
<initial-beans-in-free-pool>5</initial-beans-in-free-pool>
</pool>
<destination-jndi-name>queue/Autoshop</destination-jndi-name> ;
</message-driven-descriptor>
</weblogic-enterprise-bean>

-------------------------------------------------------------------

This is a portion of my config.xml for the weblogic server showing the JMS setup.

config.xml (weblogic)

<JMSConnectionFactory JNDIName="jms/Autoshop" Name="AutoshopFactory"
Targets="myserver" XAConnectionFactoryEnabled="true"/>
<JMSServer Name="JMSClemDEV" PagingStore="" Store="Ejb20Store" Targets="myserver">
<JMSTopic CreationTime="1105766985348" JNDIName="topic/Autoshop"
JNDINameReplicated="false" Name="TopicAutoshop"/>
<JMSQueue CreationTime="1105775501794"
ErrorDestination="ErrorQueue" ExpirationPolicy="Redirect"
JNDIName="queue/Autoshop" JNDINameReplicated="false" Name="QueueAutoshop"/>
<JMSQueue CreationTime="1106043185507" JNDIName="queue/ErrorQ"
JNDINameReplicated="false" Name="ErrorQueue"/>
</JMSServer>
<JMSFileStore Directory="ejb20filestore" Name="Ejb20Store"/>
------------------------------------------------------------------------------- ------------------


The queue that Iam writing to is "queue/Autoshop". The queue uses a persistent filestore and I can see that the file contains the messages. But when I check the console it show "MESSAGE_PENDING" = 0 and "MESSAGES" = 0!
I have some 'println' in onMessage(), but they never get printed!!..The MDB just doesn't listen to the destination!!!

Here is my onMessage() method:




Here is the code from the session bean that writes to the queue:




The QueueConnectionFactory is XA enabled..

Thanks guys,
CLement
Brian Tinnel
Ranch Hand

Joined: Aug 25, 2003
Posts: 69
Not sure if this is causing the problem, but you don't want to have a qconnect.start() in your session bean. start() is used to cause the connection to start receiving messages from the queue and is not needed if you are putting messages on the queue. However, I doubt that it is causing the problem you are seeing.

The only other thing I can think of is to make sure that your transaction attributes are all appropriate. In your case, the session bean and message bean should probably be "Required".

Finally, are you sure that there isn't another client listening to the same queue.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Please try to check the same through normal java application program instead of MDB. In general developer will get the problem related to network/lookup of Queue.
H Sivad
Greenhorn

Joined: Dec 02, 2004
Posts: 14
Originally posted by Malli Raman:
Please try to check the same through normal java application program instead of MDB. In general developer will get the problem related to network/lookup of Queue.


Yes, agreed. Then, make sure that the queue listener in the app server is configured for the queue, and that the MDBs are associated with the connection listener.
Sreenivas Mangasandra
Greenhorn

Joined: Dec 16, 2004
Posts: 10
Hi CLement,

The code is quite ok. i feel u r setting in the Web App Server are not correctly configured. I mean the Queue Listeners, Queue Connection Factories and Queue for the JNDI. and right values in it. It can be a type mistake in the name or an extra space.

U could just write a normal code to test a MDB for onMessage by manually putting a message in the queue.

Srinu.


Regards,<br /> <br />Sreenivas
clement valentine
Greenhorn

Joined: Apr 04, 2002
Posts: 19
Hi guys,
It worked when I set "transacted" to false.

Old ---> QueueSession qsession = qconnect.createQueueSession(true,0);
New ---> QueueSession qsession = qconnect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

Also I realised that Session.AUTO_ACKNOWLEDGE is 1 and not 0! For that matter I can't find out what the static value '0' is in the javax.jms.Session API. Does '0' mean NO_ACKNOWLEDGEMENT?

According to the WLS doc. when "transacted" the ackowledge value is ignored. But somehow this didn't seem to work. Can anyone explain that for me please?

Whats the effect of setting the "transacted" to false? Does it mean that a rollback is not possible if anything down the line fails?

Thanks guys,
Clement
[ January 19, 2005: Message edited by: clement valentine ]
H Sivad
Greenhorn

Joined: Dec 02, 2004
Posts: 14
Originally posted by clement valentine:
Hi guys,
It worked when I set "transacted" to false.

Old ---> QueueSession qsession = qconnect.createQueueSession(true,0);
New ---> QueueSession qsession = qconnect.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

Also I realised that Session.AUTO_ACKNOWLEDGE is 1 and not 0! For that matter I can't find out what the static value '0' is in the javax.jms.Session API. Does '0' mean NO_ACKNOWLEDGEMENT?

According to the WLS doc. when "transacted" the ackowledge value is ignored. But somehow this didn't seem to work. Can anyone explain that for me please?

Whats the effect of setting the "transacted" to false? Does it mean that a rollback is not possible if anything down the line fails?

Thanks guys,
Clement

[ January 19, 2005: Message edited by: clement valentine ]


You should use "Session.AUTO_ACKNOWLEDGE" or "Session.CLIENT_ACKNOWLEDGE" or "Session.DUPS_OK_ACKNOWLEDGE" or "Session.SESSION_TRANSACTED" -- DON'T use the literal int value. If the implementation of these values changes, (in other words, they change the int values these symbolically represent) your application will be broken. Also, someone else can look at you code and see that you want the session transacted, whereas "3" would hold no clue to your intent.

That bit of coding style aside, message beans acknowledgement is automatically handled by the container. If you use bean managed transaction then the receipt is acknowledged by the container. Either way you specify the type of acknowledgement in the deployment descriptoras either AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE. So, the way the transaction is handled depends on Weblogic's implementation and the way you write and deploy your beans.

See This ServerSide article for more details about MDBs.

H.
 
jQuery in Action, 2nd edition
 
subject: MDB onMessage() not firing....Help needed please!