blog.smart-java.nl
Ordina J-Technologies – Java Blog



DefaultMessageListenerContainer troubles in Websphere

By: Michel.Schudel, 3 February 2010

Using the Spring DefaultMessageListenerContainer makes it easy for you to connect to a jms resource like a Queue so you can pick up messages from that queue.

Using this container in Websphere (6.0, 6.1, 7) some problems occur when you want to do the following:

  • You use a resource environment reference for your destination, specified in the web.xml, for the Destination.
  • You use the property destinationName on the DefaultMessageListenerContainer in combination with a JndiDestinationResolver to look up your resource environment reference like this: java:comp/env/jms/(your destination)

problem
When you try to start the application, you will get an exception like this: javax.naming.NameNotFoundException: Name "comp/env/jms/(your destination)" not found in context "java:"., although you are sure that your resource environment reference is defined correctly.

cause
The cause of this problem lies in the fact that the lookup occurs in a Thread started by the DefaultMessageListenerContainer, which is unmanaged by Websphere. This thread will not have the jndi queue bindings in its InitialContext.

solution
You can either:

  1. Specifiy the jndi object beforehand with a JndiObjectFactoryBean, or a
    <jee:jndi-lookup id="myqueue" jndi-name="java:comp/env/jms/(your destination)"/>
    , and then
    setting the destination property of the DefaultMessageListenerContainer to the ref myqueue, so no actual lookup occurs within the thread of the listener itself.
  2. Delegate the listener’s thread to Websphere with the help of the Spring class WorkManagerTaskExecutor. You can then set the property taskExecutor on the message listener container to reference this class. See the IBM article here for details on how to do this.

3 reacties op “DefaultMessageListenerContainer troubles in Websphere”

  1. Jan-Kees van Andel zegt:

    Thanks. I’m gonna create some Spring Message Driven POJO’s soon and thy need to run in WAS 7.

    I’m bookmarking this post as a reference!

  2. Vincent zegt:

    Or, you could just go one floor up for 10 minutes… ;-)

  3. Jan-Kees van Andel zegt:

    I’ll probably do that too. :)

Laat een reactie achter

Je moet ingelogd zijn om een reactie te plaatsen.