vbNewbie
vbNewbie

Reputation: 3345

java based rabbitmq producer send message with headers

I am attempting to convert a C# version of a rabbitmq producer to one in java and the one issue I am having is figuring out how to send a message header with multiple string values. I think I may have found it but how would I add additional values to header. Current code:

 AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder();
 builder.headers(Collections.<String,Object>singletonMap("pId",ID));
 builder.headers(Collections.<String,Object>singletonMap("query",searchQ));
 pchannel.basicPublish("","best_queue",builder.build(),post.getBytes());
 System.out.println(" [x] Sent '" + msgcount.toString() + "' MESSAGES.");

But only the last header property appears. How do I get to add more values to the header?

Upvotes: 1

Views: 3073

Answers (1)

Gabriele Santomaggio
Gabriele Santomaggio

Reputation: 22682

The second one replace the first one.

Try using:

  Map<String,Object> headerMap = new HashMap<String, Object>();
  headerMap.put(key,value)
  headerMap.put(key1,value1)
  headerMap.put(key2,value2)
  builder.headers(headerMap);
  pchannel.basicPublish("","best_queue",builder.build(),post.getBytes());
  System.out.println(" [x] Sent '" + msgcount.toString() + "' MESSAGES.");

In this way should work as you expect

Upvotes: 1

Related Questions