0

I'm following the instructions for the Stock Trading sample, which outlines how to use request/reply messaging in spring-amqp: http://static.springsource.org/spring-amqp/docs/1.2.x/reference/html/sample-apps.html#d4e742

Looking at the ServerHandler class which is a Message-driven POJO that happens to be also capable of sending reply Messages ... I don't see a place where we can inject MessageProperties for content-type

I've tweaked this sample and I want to return an xml message posing as a simple string ... but when ServerHandler posts my reply to RabbitMQ, it looks like:

properties:
  correlation_id:   9873f420-89e5-465d-aa60-ec9281ee48ae
  priority: 0
  delivery_mode:    2
  headers:  
    __TypeId__: java.lang.String
  content_encoding: UTF-8
  content_type: application/json

payload:
  "<?xml version='1.0' encoding='UTF-8'?>\n<stuff></stuff>

And ultimately (my guess is) my client which should be reading this ... is unable to parse the object because of the content_type being set incorrectly to application/json and my usecase fails so I receive null back as the reply.

Q) Does anyone know how to set content-type for the reply in spring-amqp Request/Reply Messaging?


Update#1

Q) Perhaps what I need is to make sure that jsonMessageConverter is only used for reading messages off of the requestQueue and not when I want to put back a reply onto the responseQueue ... any idea on how to configure that? This is a snippet from my current appContext.xml file:

<listener-container
    concurrency="5"
    connection-factory="connectionFactory"
    message-converter="jsonMessageConverter"
    xmlns="http://www.springframework.org/schema/rabbit">
    <listener ref="serverHandler" method="handleMessage" queue-names="#{queue.name}" />
</listener-container>
pinepain
  • 12,453
  • 3
  • 60
  • 65
pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84

1 Answers1

2

If you are saying you are receiving JSON but want to return XML, you could use a custom MessageConverter that delegates to the JsonMessageConverter on the inbound side and a SimpleMessageConverter on the outbound side; it can also set the content-type message property as desired.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • Thanks Gary, can you point me to the spring docs or provide a sample of how separate inbound and outbound converters can be configured in a `listener-container`? – pulkitsinghal Jun 13 '13 at 12:59
  • 1
    You can't directly; I was suggesting you do something like this https://gist.github.com/garyrussell/5773846 – Gary Russell Jun 13 '13 at 13:55
  • Thank You! Once I set it to `AsymmetricMessageConverter` there was actually no more need to set the content-type `because` the `SimpleMessageConverter` for the outbound message .. already sets it to `text/plain` on its own. BUT sadly it turns out I still keep getting a `null` reply back on the client-side which initiated `convertSendAndReceive` even though the message has been delivered to the reponse/reply queue. – pulkitsinghal Jun 13 '13 at 15:01
  • Would you mind taking a look at this one too because the underlying issue for me still hasn't gone away: http://stackoverflow.com/questions/17090852/null-response-for-spring-ampq-request-reply-messaging – pulkitsinghal Jun 13 '13 at 15:20