0

I'm using RabbitMQ as message broker. I have a consumer and a producer. So far I have created a payload with few primitive attributes. The problem is, as long as I need more information from the payload in my consumer, I need to change payload so I can handle in the consumer: this task at the end may be heavy.

I was wondering if I could use some kind of a Map as payload or it is not recommended? Like this, I have a generic payload.

On the other hand, we have Serializable DTO in our application. I guess I could create a Payload containing DTO?

I'm trying to figure out the best way to do it :)

Rapster
  • 484
  • 1
  • 5
  • 23

1 Answers1

0

if you need extra information you could use message properties:

 AMQP.BasicProperties.Builder builder =
                        new AMQP.BasicProperties().builder();
                        Map<String,Object> headerMap =
                        new HashMap<String, Object>();
                        headerMap.put("mykey1", myvalue1);
headerMap.put("mykey2", myvalue2);
builder.headers(headerMap);


channel.basicPublish("","myqueue",builder.build(),"message".getBytes());

Using headerMap you can add or remove info without modify your message

hope it helps

Gabriele Santomaggio
  • 21,656
  • 4
  • 52
  • 52