Hi,
On 09/06/2010 02:00 PM, Glen Mazza wrote:
> Hello, I'm new to ActiveMQ messaging queues and unsure if I can place
> and subsequently read POJO's from them. I have no problems getting
> Strings to work it's just using POJO's that is creating the problem
> for me.
You should be able to send Serializable objects through the queues, but
I would like to suggest you look into other serialization methods like
Protobufs or JSON.
Is DoubleIt serializable?
Regards,
Tarjei
>
> Here's how I place a DoubleIt POJO on the queue in Camel:
> ProducerTemplate template = context.createProducerTemplate();
> context.start();
> DoubleIt doubleIt = new DoubleIt();
> doubleIt.setNumberToDouble(5);
> template.sendBody("jms:queue:numbersToDouble", doubleIt);
> Thread.sleep(24000);
> context.stop();
>
> Here's my route:
> from("jms:queue:numbersToDouble").process(new DoubleItReader());
>
> And here's my implementation of DoubleItReader:
>
> public class DoubleItReader implements Processor {
>
> @Override
> public void process(Exchange e) {
> DoubleIt response = e.getIn().getBody(DoubleIt.class);
> System.out.println("This was returned - Body: " +
> response.getNumberToDouble());
> }
>
> }
>
> The above returns this error when I try to run Camel:
> [INFO] [aultMessageListenerContainer-1] DefaultErrorHandler
> ERROR Failed delivery for exchangeId:
> ID:gmazza-desktop-54558-1283773608538-2:1:1:1:1. Exhausted after
> delivery attempt: 1 caught: java.lang.NullPointerException
> [INFO] java.lang.NullPointerException
> [INFO] at
> camel.SOAPResponseReader.process(SOAPResponseReader.java:12)
> [INFO] at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>
> [INFO] at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>
>
> If I try this conversion line instead:
> DoubleIt response = (DoubleIt) e.getIn().getBody(Object.class);
> I get this error:
> [INFO] Caused by: java.lang.ClassCastException:
> org.apache.camel.component.jms.JmsMessage cannot be cast to
> org.example.schema.doubleit.DoubleIt
> [INFO] at
> camel.SOAPResponseReader.process(SOAPResponseReader.java:11)
> [INFO] at
> org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50)
>
> [INFO] at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
>
> [INFO] at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)
>
>
> Does this mean I'm basically limited only to Strings (or to what?) for
> the second parameter of the
> "template.sendBody("jms:queue:numbersToDouble", ???)" command--or am I
> doing something else wrong?
>
> Thanks,
> Glen
>
--
Regards / Med vennlig hilsen
Tarjei Huse
Mobil: 920 63 413