Announcement Announcement Module
No announcement yet.
cafe-amqp example, runtime exception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • cafe-amqp example, runtime exception

    I've pulled the source for the latest spring integration examples and am having trouble with the last of four steps. The demo creates 100 drink orders and puts them onto a RabbitMQ queue. I can see that these have been created through the rabbitmq administration panel.

    The last step of the cafe-amqp demo is to run CafeDemoAppOperationsAmqp. What I am encountering is an error processing the payload of the message in the AmqpInboundChannelAdapter, which has the payload as an array of bytes. This might not be a problem; perhaps the payload is always an array of bytes. But when the payload is being transformed by the AbstractPayloadTransformer, an exception is thrown because the transformer wants a string instead of a byte array.

    The partial stack is shown below:

    Caused by: java.lang.ClassCastException: [B cannot be cast to java.lang.String
    at org.springframework.integration.json.JsonToObjectT ransformer.transformPayload(JsonToObjectTransforme
    at org.springframework.integration.transformer.Abstra ctPayloadTransformer.doTransform(AbstractPayloadTr
    at org.springframework.integration.transformer.Abstra ctTransformer.transform( 3)
    I suppose I will inject my own transformer before the JsonToObjectTransformer is invoked to change the bytes to a string, but I'm sure there must be something wrong for this to happen.

    Any ideas?

  • #2
    I was able to get it to work by injecting the transformer as I mentioned I would try. The transformer is basic:

    public class ByteArrayToJsonTransformer extends AbstractTransformer {
        protected Object doTransform(Message<?> message) throws Exception {
            Object payload = message.getPayload();
            return new String((byte[]) payload);
    I injected this in the cafe-amqp configuration file cafeDemo-amqp-operations-xml.xml, just after the inbound-channel-adapter definition:

        <bean class="com.sellis.transfomers.ByteArrayToJsonTransformer" id="byteArrayToJsonTransformer"/>
        <int:transformer input-channel="byteToJsonChannel" output-channel="jsonOrders"
        <int:json-to-object-transformer id="json-to-order" input-channel="jsonOrders" output-channel="preOrders"
                                        type="" />
    Now the demo is running for me.


    • #3
      When did you clone the repo? Have you pulled recent updates?

      This problem ( was fixed Jan 10th - - see the 6th commit down.

      I just pulled Gunnar's changes and all worked fine for me.


      • #4
        It was before the fix was put in. I'll pull and try again. I have to remember to check the open issues as well as the forums before posting here. Thanks for trying it out. Reading the text of the issue, it makes sense that the type of data would not be json text when the payload is processed by the transformer.


        • #5
          As a follow up, I didn't pull the new samples since I have made some minor changes, such as adding an error logger. But I integrated Gunnar's changes and it works perfectly. This was a good learning experience, as my own solution was a hack at best; the addition of the content-type to the transformer is so much nicer. Thanks.