1
votes

I have an issue in getting the message to spring-cloud-stream spring-boot app. I am using rabbitMq as message engine. Message producer is a non spring-boot app, which sends a message using Spring RestTemplate.

Queue Name: "audit.logging.rest"

The consumer application is setup to listen that queue. This app is spring-boot app(spring-cloud-stream).

Below is the consumer code

application.yml

cloud:
    stream:
      bindings:
        restChannel:
          binder: rabbit
          destination: audit.logging
          group: rest

AuditServiceApplication.java

@SpringBootApplication
public class AuditServiceApplication {
@Bean
    public ByteArrayMessageConverter byteArrayMessageConverter() {
        return new ByteArrayMessageConverter();
    }
  @Input
    @StreamListener(AuditChannelProperties.REST_CHANNEL)
    public void receive(AuditTestLogger logger) {
    ...
   }

AuditTestLogger.java

    public class AuditTestLogger {

    private String applicationName;

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }
}

Below is the request being sent from the producer App in JSON format.

{"applicationName" : "AppOne" }

Found couple of issues: Issue1: What I noticed is the below method is getting triggered only when the method Parameter is mentioned as Object, as spring-cloud-stream is not able to parse the message into Java POJO object.

 @Input
        @StreamListener(AuditChannelProperties.REST_CHANNEL)
        public void receive(AuditTestLogger logger) {

Issue2:

When I changed the method to receive object. I see the object is of type RMQTextMessage which cannot be parsed. However I see actual posted message within it against text property.

I had written a ByteArrayMessageConverter which even didn't help.

Is there any way to tell spring cloud stream to extract the message from RMQTextMessage using MessageConverter and get the actual message out of it.

Thanks in Advance..

2

2 Answers

0
votes

RMQTextMessage? Looks like it is a part of rabbitmq-jms-client.

In case of RabbitMQ Binder you should rely only on the Spring AMQP.

Now let's figure out what your producer application is doing.

Since you get RMQTextMessage as value for the @StreamListener method that says me that the sender really uses rabbitmq-jms-client for producing, and therefore the real AMQP message in queue has that RMQTextMessage as a wrapper for real payload.

Why don't use Spring AMQP there as well?

0
votes

It's a late reply but I have the exact problem and solved it by sending and receiving the messages in application/json format. use this in the spring cloud stream config.

content-type: application/json