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.

    require 'qpid_proton'

    msg = Qpid::Proton::Message.new
    msg.address = "0.0.0.0"
    msg.content = "Hello, Proton!"

    messenger = Qpid::Proton::Messenger.new
    messenger.start
    messenger.put(msg)
    messenger.send

    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.

    require 'qpid_proton'

    msg = Qpid::Proton::Message.new

    messenger = Qpid::Proton::Messenger.new
    messenger.start
    messenger.subscribe("~0.0.0.0")

    messenger.receive(1)
    messenger.get(msg)

    puts "RECV:"
    puts "Address: #{msg.address}"
    puts "Content: #{msg.content}"

    messenger.stop
    exit 0

Would You Like to Know More?