1

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.