I'm having an issue where headers that I explicitly set on a Message object get overwritten. It seems you're forced to use a MessagePostProcessor in order to add headers to a message. As an example, the following method creates a new instance of RabbitMessageProperties in RabbitTemplate class:
This method is delegated to from the following method:Code:public void convertAndSend(String exchange, String routingKey, final Object object) throws AmqpException { send(exchange, routingKey, new MessageCreator() { public Message createMessage() { return getRequiredMessageConverter().toMessage(object, new RabbitMessageProperties()); } }); }
Since I passed in a Message object with the headers I needed, I expected message and headers to be present but the headers were lost because of the new instance of RabbitMessageProperties created on the delegate method. Here is my code that creates a message and the desired headers:Code:public void convertAndSend(String routingKey, final Object object) throws AmqpException { convertAndSend(this.exchange, routingKey, object); }
Is this the desired behavior? If so, what's the best way to add user-defined headers to a message before sending it?Code:MessageProperties mProperties = new RabbitMessageProperties(); mProperties.setHeader("bondId", request.getBondId()); mProperties.setHeader("jobName", request.getJobName()); mProperties.setHeader("filename", outputFile.getName()); mProperties.setHeader("startTime", startTime); mProperties.setHeader("stopTime", stopTime); Message msg = new Message(outputFileBArray, mProperties); getRabbitTemplate().convertAndSend(request.getCallbackQueue(), msg);


Reply With Quote