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

radisb radisb at gmail.com
Sun Apr 25 18:10:44 BST 2010

Hi matthias, 
 I looked into the source code of MessageProperties.XXXXX and the reason for
the problem is that   MessageProperties.XXXXX are static final. This means
that either I am mistaken in thinking that their use were as a shortcut for
construction of BasicProperties, or they shouldnt be static. 
But I then read in the javadoc that they are "Constant holder class with
useful static instances of AMQContentHeader. These are intended for use with
Channel.basicPublish". This makes sense but the problem is that the
BasicProperty class holds user data (the headers) that is to be set and get
by the user. So the kind of use  MessageProperties.XXXXX the javadoc
suggests, is useless for me because this way how am I going to set my
headers before calling basicPublish? I have to create a fresh
BasicProperties instance to set the headers and then pass them to
basicPublish. And since MessageProperties.XXXX is static , the only way to
do that is create BasicProperties by constructor. The constructor has many
boilerplate arguments, thats why I though the MessageProperties where a
convinience for construction. It seems the current design of
MessageProperties assumes the user is only making use of the body and not
the headers. For those users that they need access to headers (and I think
they are a lot) shouldn't we provide the same convinience? :wistle::-D

Thanks a lot,

Bill Radis.

Matthias Radestock-3 wrote:
> Hi,
> 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 
> concurrently.
> To avoid this, you should clone() the object first and then use/modify 
> the clone instead.
> Regards,
> Matthias.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

View this message in context: http://old.nabble.com/Problem-with-BasicProperties-%28bug-%29-tp28351417p28357380.html
Sent from the RabbitMQ mailing list archive at Nabble.com.

More information about the rabbitmq-discuss mailing list