Add custom headers to messages using stomp for perl and python

975 views
Skip to first unread message

Steven Turner

unread,
Dec 5, 2013, 11:52:45 AM12/5/13
to stomp...@googlegroups.com
Hi,
I  have a use case where some clients are sending text messages which serialized as XML and some clients send messages serialized as JSON. I want to deserialize both types of messages in my application. Is there a way to add custom headers to the message which may indicate what kind of serialization is done?

For eg. clients can add a header 'MessageType' and specify its value as XML or JSON depending on the serialization technique.

I would really appreciate a quick response on this.

Thanks,
Steven

Shawn Dempsay

unread,
Dec 5, 2013, 12:33:58 PM12/5/13
to stomp...@googlegroups.com
As long as you are not overwriting a well known header like "content-length", there is no reason why you can't add your own. In our products we do just that.

-- Shawn Dempsay
--
You received this message because you are subscribed to the Google Groups "stomp-spec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stomp-spec+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Steven Turner

unread,
Dec 6, 2013, 1:05:37 AM12/6/13
to stomp...@googlegroups.com
Can you point me to some example code on how to do it in perl and python? Or if you can provide some sample code here like a method call. 

Really appreciate your quick response.

Thanks,
Steven

Shawn Dempsay

unread,
Dec 6, 2013, 9:44:14 AM12/6/13
to stomp...@googlegroups.com
Sorry we built our own C# version from the spec, so while I know you can do it, I don't know how you would do it using another library.

-- shawn

Jason Briggs

unread,
Dec 7, 2013, 5:07:22 AM12/7/13
to stomp...@googlegroups.com

Serialises to dict, but I think that’s the scenario you’re talking about.

Kevin Esteb

unread,
Dec 8, 2013, 1:47:19 AM12/8/13
to stomp...@googlegroups.com
On 12/07/2013 02:07 AM, Jason Briggs wrote:

Serialises to dict, but I think that�s the scenario you�re talking about.

On 6 Dec 2013, at 14:44, Shawn Dempsay <sdem...@gmail.com> wrote:

Sorry we built our own C# version from the spec, so while I know you can do it, I don't know how you would do it using another library.

-- shawn

On 12/6/2013 12:05 AM, Steven Turner wrote:
Can you point me to some example code on how to do it in perl and python? Or if you can provide some sample code here like a method call.�

Really appreciate your quick response.

Thanks,
Steven

On Thursday, December 5, 2013 11:03:58 PM UTC+5:30, sdempsay wrote:
As long as you are not overwriting a well known header like "content-length", there is no reason why you can't add your own. In our products we do just that.

-- Shawn Dempsay

On 12/5/2013 10:52 AM, Steven Turner wrote:
Hi,
I �have a use case where some clients are sending text messages which serialized as XML and some clients send messages serialized as JSON. I want to deserialize both types of messages in my application. Is there a way to add custom headers to the message which may indicate what kind of serialization is done?

For eg. clients can add a header 'MessageType' and specify its value as XML or JSON depending on the serialization technique.

I would really appreciate a quick response on this.

Thanks,
Steven
--
You received this message because you are subscribed to the Google Groups "stomp-spec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stomp-spec+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "stomp-spec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stomp-spec+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "stomp-spec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stomp-spec+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "stomp-spec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stomp-spec+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

If you are using Perl, you can use the XAS middleware suite, and it is fairly easy to do what you want.

Example:

� my $stomp = XAS::Lib::Stomp::Utils->new(-target => '1.0');
� my $frame = $stomp->send(
���� -destination => '/queue/foo',
���� -message => $data
� );
� $frame->headers->add('x-data-type', 'json');
� my $message = $frame->as_string;


nikipore

unread,
Dec 8, 2013, 6:05:26 AM12/8/13
to stomp...@googlegroups.com
I find this discussion off-topic because STOMP allows to add as many headers as you wish as long as you stay out of the way of the (very few and well-identifiable) headers which the STOMP protocol reserves for itself, plus those of your broker. So it really amounts to consulting the documentation of your client of choice. With stompest (the Python client I am maintaining), it is as easy as

CONFIG = StompConfig('tcp://host:port')
QUEUE = '/queue/test'

client = Stomp(CONFIG) client.connect() client.send(destination=QUEUE, body=u'{"a": "b"}', headers={'mime-type': 'application/json'})
client.disconnect()

The full documentation is here. If you are going to use stompest, feel free to post your question in the stompest group.

Steven Turner

unread,
Dec 11, 2013, 12:38:13 AM12/11/13
to stomp...@googlegroups.com
Thanks JRB, kesteb and nikipore. Your examples worked perfectly.

-
Steven
Reply all
Reply to author
Forward
0 new messages