activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Retzlaff <dretzl...@gmail.com>
Subject ClassCastException with ObjectMessages and MessageListeners between Web Apps
Date Tue, 24 Aug 2010 23:42:23 GMT
When ActiveMQ deserializes an ObjectMessage, it uses the current thread's
context ClassLoader. This strategy does not work for my combination of
Tomcat and JMS MessageListeners, and I'm wondering if I'm missing something.

I have multiple web applications deployed in Tomcat, with a shared VM broker
ConnectionFactory configured in Tomcat's context.xml. Let's call the
applications AppA and AppB. If AppA opens a JMS connection first, the
connection's threads' ClassLoader is AppA's. If AppB receives an
ObjectMessage from AppA using a MessageListener, a ClassCastException is
thrown when downcasting.

As a workaround, I have created a thread pool in AppB dedicated to pulling
messages with MessageConsumer.receive(). This way AppB's context ClassLoader
is used during deserialization and the downcast succeeds. However, this
feels inelegant, and I'm surprised at my inability to find any other
discussion of this subtle gotcha.

Any suggestions? Maybe I shouldn't be sharing a my ConnectionFactory among
web applications?

Regards,
Dan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message