Spring AMQP 1.3.5 correlation id

328 views Asked by At

Does anyone know why Spring Integration (AMQP 1.3.5) requires the correlation-id to be a byte array? Rabbit's AMQP-Client 3.3.5 takes a String for the correlation-id in the AMQP.BasicProperties class. Doesn't Spring need to convert the byte array to this String at some point? We're finding that the correlation-id in the message Rabbit sends is still a byte array, and is never converted to a String. Any insight?

1

There are 1 answers

0
Gary Russell On

Good question, I have no insight; it was before my time on the project and it's a day one issue.

Spring AMQP converts the byte[] to a String in DefaultMessagePropertiesConverter (outbound); invoked by the RabbitTemplate using UTF-8 by default. The resulting string is added to the BasicProperties.

On the listener container (inbound) side, UTF-8 is used unconditionally.

The rabbit client converts to byte[] when writing to the wire (in ValueWriter.writeShortStr()), unconditionally using charset UTF-8.

So, unless you change the charset in RabbitTemplate (which would be bad), it's a no-op (but unnecessary if you already have a String).

I can only speculate that, since MessageProperties is an abstraction (and not tied to RabbitMQ), some other client had it as a byte[] when the abstraction was being designed.

Since we only have a rabbitmq implementation, I wouldn't be averse to adding an optimization to the abstraction to avoid the unnecessary conversion.

Feel free to open an Improvement JIRA Issue and we'll take a look at it for the upcoming 1.5 release.