Search code examples
spring-cloud-streamspring-rabbit

Setting properties on message produced for RabbitMQ


We are using spring cloud stream to consume and produce messages for Rabbitmq.

We have a requirement to read Correlation Id from the incoming message and set it on the produced message.

We are able to read the same using message.getHeaders() but how to set it on the outgoing message?

When using MessageBuilder.setHeader() we are able to send the value but in rabbit management console it appears under headers and not properties.

Both the producer and consumer applications for us are not using spring cloud stream.


Solution

  • Are you setting the AmqpHeaders.CORRELATION_ID header? That is mapped to/from the property. If you are using anything else, it will be set as a header.

    EDIT

    It works fine for me...

    @Bean
    public ApplicationRunner runner(MessageChannel output) {
        return args -> output.send(new GenericMessage<>("foo",
                Collections.singletonMap(AmqpHeaders.CORRELATION_ID, "foo")));
    }
    

    and

    enter image description here

    Are you sure you're using the right constant?