Menu Search

from __future__ import print_function, unicode_literals
import optparse
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container

class Send(MessagingHandler):
    def __init__(self, url, messages):
        super(Send, self).__init__()
        self.url = url
        self.sent = 0
        self.confirmed = 0 = messages

    def on_start(self, event):

    def on_sendable(self, event):
        while and self.sent <
            msg = Message(id=(self.sent+1), body={'sequence':(self.sent+1)})
            self.sent += 1

    def on_accepted(self, event):
        self.confirmed += 1
        if self.confirmed ==
            print("all messages confirmed")

    def on_disconnected(self, event):
        self.sent = self.confirmed

parser = optparse.OptionParser(usage="usage: %prog [options]",
                               description="Send messages to the supplied address.")
parser.add_option("-a", "--address", default="localhost:5672/examples",
                  help="address to which messages are sent (default %default)")
parser.add_option("-m", "--messages", type="int", default=100,
                  help="number of messages to send (default %default)")
opts, args = parser.parse_args()

    Container(Send(opts.address, opts.messages)).run()
except KeyboardInterrupt: pass

Download this file