Search code examples
rubyactivemq-classicstomp

Setting a message property to be an integer using stomp (ruby) to ActiveMQ


I have to set a custom message property named SEQUENCE to be an integer when I send a message to activemq. As the activemq site explains, the STOMP protocol deals only with strings. So from what I understand there is no way to do this using STOMP. Is there any other way using Ruby I can set a header to have an integer value?

From http://activemq.apache.org/cms/stomp-support.html :

Message Properties in Stomp CMS Since Stomp is strictly text-based, it does not support a way to specify the type of message properties (called "header" in stomp lingo). This means that a property sent as an integer could be read by a Stomp CMS client as any of: string, integer, short, long, etc.

When a Java client, for example, sends a message to the broker with an integer property ("myval"=1), the broker adapts the message from openwire to stomp and in the process converts the property "myval" to the string "1" and sends the message to the client. The client receives the string, but allows the user to read this value in any way that will work successfully with the std::istringstream >> operator.

The same goes for writing values to an outgoing message. You can call any of the methods (e.g. setIntProperty). The resulting value that goes out on the wire is still a string, however.


Solution

  • Anything sent on the wire would need to be as a UTF-8 encoded string as that is all that STOMP allows (it is a text based protocol). The broker sees the values in the properties as strings and will convert them if going out to OpenWire or AMQP into properly encoded strings for those protocols. On the client you can use whatever language features exist to convert the string to a numeric form and would need to handle errors that might result from faulty decoding.