0

I would like to generate responses on my queue with content type application/json because payload contains the json object.

But...

Don't know why my spring-stream (based on RabbitMQ) always generates the message with below headers (payload is correct and has JSON form).

(view from rabbit ui)
properties:
    delivery_mode:  2
    headers:    
      contentType:  text/plain
      originalContentType:  application/json;charset=UTF-8
    content_type:   text/plain

So the content_type equals to text/plain instead of application/json;charset=UTF-8.

I have tried to set content-type in configurations like:

spring:
  cloud:
    stream:
      default:
        content-type: application/json
      bindings:
        my-channel:
          content-type: application/json
          destination: my-channel-rs
          producer:
            exchange-type: direct
            max-length: 1000

but did not help.

I have the feeling that in correct response the single header content-type should exist with value "application/json".

But maybe I am wrong? Is anybody able to explain above behaviour?

2 Answers 2

2

It appears you are using 1.3 version of S-C-Stream. Could you please confirm? We can certainly take a look. Also, FWIW, the whole 'originalContentType' issue is not a problem as long as you have a consumer that is SCSt application (as it's going to be reset to what you expect), but I am assuming that it is not, correct?

Also, any chance you can upgrade to 2.0.0.M3. There has been a lot of improvements around contentType resolution.

4
  • originalContentType: application/json;charset=UTF-8 - the rabbit binder is not intended for communication with arbitrary rabbitmq applications. Use the rabbit sink for that purpose. Commented Nov 28, 2017 at 15:02
  • 1. Yes it is the 1st case when my consumer does not base on a s-c-stream :) It is totally different technology, developed by someone else. 2. Version of spring-cloud-stream is Chelsea.SR2 (spring cloud dependencies = Dalston.SR4). 3. Upgrade to 2.0.0.M3? Application works on production. I would like rather wait for official release of spring boot 2 with spring cloud attached. Commented Nov 28, 2017 at 15:09
  • @GaryRussell you say that I can't use spring-cloud-stream as a producer of messages for consumers which don't base on spring-cloud-stream? What do you mean by "Rabbit Sink"? Commented Nov 28, 2017 at 15:17
  • 1
    Yes; that is what I am saying (at least until 2.0). The rabbit sink is a spring-cloud-stream app that receives messages from (any) Spring Cloud Stream binder and publishes messages to rabbitmq. Commented Nov 28, 2017 at 15:22
0

I had a similar issue. I needed the underlying spring-amqp to use the "content-type" header to set the actual content type. Spring-amqp figures it out by inspecting the class of the message payload regardless of the "content-type" header.

I created a pull request that may or may not be accepted: https://github.com/spring-projects/spring-amqp/pull/763/commits/25e4f9adf523a802ac5f26dd373eff8bb764fb49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.