[rabbitmq-discuss] Problem with BasicProperties (bug?)

Matthias Radestock matthias at rabbitmq.com
Sun Apr 25 12:24:07 BST 2010


radisb wrote:
> The problem is in the forwarding threads code. If before forwarding the
> message, the thread recreates the BasicProperties and sends a fresh
> BasicProperties , this causes the consumer on Replies to lose messages and
> get duplicates in their place. Sometimes the forwarder throws null pointer
> exception because it cant find the header that has the key(This cant happen
> because all messages are assigned one before sending). What is strange is
> that if the 2 forwarders are started in separate JVMs the problem
> disappears.
 > [...]
> 	BasicProperties props = MessageProperties.PERSISTENT_TEXT_PLAIN;
>       [...]
> 	props.setHeaders(new HashMap<String, Object>());

That last line ends up modifying the 
MessageProperties.PERSISTENT_TEXT_PLAIN object. That's bad in itself, 
but made worse by the fact that you have multiple threads doing this 

To avoid this, you should clone() the object first and then use/modify 
the clone instead.



More information about the rabbitmq-discuss mailing list