Getting Started with Messenger

The Proton Messenger interface lets you get started sending and receiving messages easily.

Sending a Single Message

We create a message, then set its address and content. We create and start a messenger, put the message, and send it.
Finally, we stop the messenger.

    import sys
    from proton import *

    messenger = Messenger()
    messenger.start()

    msg = Message()
    msg.address = "amqp://0.0.0.0"
    msg.body = unicode("Hello, Proton!")
    messenger.put(msg)
    messenger.send()

    print "sent: ", msg.body

    messenger.stop()

Receiving a Single Message

We create a message that we will use to receive to. We create and start a messenger, then subscribe to our address. Please note the use of the tilde at the beginning of the incoming address. We receive a single message to our incoming queue, and then dequeue it into the message structure we created earlier. Print out the data, and stop the messenger.

    import sys
    from proton import *

    msg = Message()

    messenger = Messenger()
    messenger.start()
    messenger.subscribe("amqp://~0.0.0.0")

    messenger.recv()
    messenger.get(msg)

    print "received:", msg.body

    messenger.stop()

Would You Like to Know More?