RabbitMQ Message Properties

11,144

Solution 1

I think you may add anything you like to the header. However, there is a field called "contentEncoding", which I think is better for this situation. You may just put "gzip", "deflate", or the compression algorithm in this field, take a look at this page for those encoding defined for HTTP: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5

Solution 2

you could use a wrapper for it as:

    public class wrapper(){
    public boolean isZipped;
    public String serializedMessage;
}

and then serialize this message with Java Serializable Object to Byte Array

or you can use this code:

persistentBasic = persistentBasic.builder().headers(filter).build();

and put your appropriate filter in header.

Share:
11,144
Arash Zareh
Author by

Arash Zareh

Updated on June 04, 2022

Comments

  • Arash Zareh
    Arash Zareh almost 2 years

    I have a code like this in RabbitMQ :

    byte[] rawBytes = serialize(trxEntities);    
    byte[] zipped = rawBytes;  
    if (shouldBeCompress) {  
    zipped = compressor.compress(rawBytes);  
    }  
    BasicProperties persistentBasic = MessageProperties.PERSISTENT_BASIC;  
    channel.basicPublish("", queueName, persistentBasic, zipped);  
    

    As you see some of my messages should be compress along witch some others shouldn't.
    Is there any way I could set any properties to tell the consumer that "hey! this is a zipped message" ?

    PS. does "com.rabbitmq.client.AMQP.BasicProperties.BasicProperties(..., Map headers, ...)" help me? I mean could I set any parameter in BasicProperties.header ?

  • wbyoung
    wbyoung about 7 years
    Shouldn't type & encoding be similar to how it's used more broadly? i.e. stackoverflow.com/a/23600787/98069