Question

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>
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top