Hi Dejan,

the stomp.py code only supports this single transformation type at the
moment, and turns the python dict into an XML string as follows:

  def __convert_dict(self, payload):
        """
        Encode python dictionary as <map>...</map> structure.
        """
        xmlStr = "<map>\n"
        for key in payload:
            xmlStr += "<entry>\n"
            xmlStr += "<string>%s</string>" % key
            xmlStr += "<string>%s</string>" % payload[key]
            xmlStr += "</entry>\n"
        xmlStr += "</map>"

        return xmlStr

Does this logic make sense ? When I look in the activemq console I see
a message body of "{field2=bar, field1=foo}" which makes me think it
's doing the right thing.

Just for completeness and to document it in the thread, to subscribe
and get these message bodies back again, you need to do :

      conn.subscribe(destination=dest, ack='auto',
headers={'transformation' : 'jms-object-xml'})

Currently this doesn't do the conversion back into a dict
automatically and will just return the xml in the message body, but
I'll look at how we can put that functionality into stomp.py

At the same time I'll look at adding additional json conversion to the
stomp.py library.

cheers,

James.


2009/10/30 Dejan Bosanac <de...@nighttale.net>:
> James,
>
> thanks for great example. Shouldn't it be jms-map-json in this example
> however?
>
> Dan, you can also take a look at PHP example here
> http://stomp.fusesource.org/documentation/php/book.html#_message_transformation
>
> Cheers
> --
> Dejan Bosanac - http://twitter.com/dejanb
>
> Open Source Integration - http://fusesource.com/
> ActiveMQ in Action - http://www.manning.com/snyder/
> Blog - http://www.nighttale.net
>
>
> On Fri, Oct 30, 2009 at 11:26 AM, James Casey <jamesc....@gmail.com> wrote:
>
>> Hi Dan,
>>
>> for stomp.py, here's the code snippet to do what you need to do:
>>
>>    dest='/queue/test.foo'
>>    conn = stomp.Connection([(HOST,PORT)])
>>    conn.start()
>>    conn.connect()
>>    message = {'field1' : 'foo', 'field2' : 'bar'}
>>
>>    conn.send(message, destination=dest, headers={'transformation' :
>> 'jms-map-xml'}, ack='auto')
>>    conn.disconnect()
>>
>> Note we pass in a dict as the payload, along with the transformation
>> type 'jms-map-xml'.
>>
>> cheers,
>>
>> James.
>>
>>
>> 2009/10/30 ngcdan12 <gameoperati...@hotmail.com>:
>> >
>> > Hello Dejan,
>> >
>> > Python is sending mapmessages directly to the MQ server :).
>> >
>> > I am wondering about the Stomp protocol.  The example you listed below is
>> > for a Java implementaion of Stomp.  I am actually having a problem with
>> the
>> > MapMessage being sent from the Python side.  So I would need to convert
>> the
>> > mapmessage to an xml object, then, using stomp headers convert that
>> object
>> > to a map message then send it correct?  The problem is I need to do that
>> in
>> > Python and have been unable to find how to do so since all the examples
>> are
>> > listed in java.  Could you clarify on using Python to create an xml
>> object,
>> > convert to a map message then send it to Java?  Or is that not possible.
>>  I
>> > have been looking at some modules like Stompy and stomppy but have not
>> been
>> > able to create a working messageListener.
>> >
>> > Thanks,
>> >
>> > Dan
>> >
>> >
>> > Hi,
>> >
>> > are you sure you're sending map messages from Python?
>> >
>> > If you use Stomp protocol, you have to send your data xml or json encoded
>> > and use "transformation" header to specify how data should be converted
>> to
>> > Java. I suggest you read this
>> >
>> http://cwiki.apache.org/confluence/display/ACTIVEMQ/Stomp#Stomp-Messagetransformationsand
>> > look at StompTest (
>> >
>> http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?view=markup
>> )
>> > for some more examples.
>> >
>> > You can also use py-activemq (http://code.google.com/p/pyactivemq/) lib
>> > which can use OpenWire and CMS API to send map messages naturally.
>> >
>> > Cheers
>> > --
>> > Dejan Bosanac - http://twitter.com/dejanb
>> >
>> > Open Source Integration - http://fusesource.com/
>> > ActiveMQ in Action - http://www.manning.com/snyder/
>> > Blog - http://www.nighttale.net
>> >
>> >
>> > --
>> > View this message in context:
>> http://www.nabble.com/MapMessages-from-Python-to-Java-tp26070536p26123324.html
>> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>> >
>> >
>>
>

Reply via email to