0
votes

I am using Spring integration to connect to JMS Messaging queues. JMS Provider I am using is Apache ActiveMQ.

I have following class which reads JMS messages (having ServiceActivator method):

@Component
public class MessageReader
{

@ServiceActivator
public Entity onMessage(Message<Entity> inboundMessage) {

    System.out.println(" -------Message Read Start--------");

    System.out.println(inboundMessage.getHeaders());

    System.out.println(" -------Message Headers Reading completed--------");

    Entity payload = null;


    try{

        payload = inboundMessage.getPayload();
        System.out.println(" -------Message Read End--------");
    }catch(Exception e){
        e.printStackTrace();
    }


    return payload;
}
}

Over here, Entity is a POJO in my application.

While reading message from JMS-queue, I get following exception:

java.lang.ClassCastException: org.apache.activemq.command.ActiveMQObjectMessage cannot be cast to com.poc.pojo.Entity

How should I solve this?

Thanks

2
It looks like you are trying to use the framework(s) incorrectly; you need to show the full stack trace and exactly how you are configuring the app.Gary Russell

2 Answers

0
votes

See your stacktrace, ClassCastException,

  • First see your Entity, what interface has implement?
  • Second inboundMessage.getPayload().getClass(), implement same interface ActiveMQ required?

    • Solution for this the both class implement same interface.
    • Other reader one class make a converter other class.
    • Other problema, spring configuration correct for use integration ActiveMQ
0
votes

Looks like your <int-jms:message-driver-channel-adapter> is configured with the `extract-payload="false".

In that case the entire JmsMessage is presented as a payload of Spring Integration Message. But as you see your ServiceActivator expects exactly the body of that JmsMessage.