def main(argv=None): opts = setup_options(argv) core.setup_logging(level=logging.WARN if opts.quiet else logging.DEBUG) transport_url = core.rabbit_connection_url(driver='rabbit') transport = oslo_messaging.get_transport(cfg.CONF, transport_url) target = oslo_messaging.Target(topic=opts.topic, server=opts.server_name) control = ServerControlEndpoint(None) control.response_delay = opts.response_delay control.num_messages = opts.num_messages endpoints = [ control, ] server = oslo_messaging.get_rpc_server(transport, target, endpoints, executor='eventlet') control.server = server control.num_messages = opts.num_messages t_start = time.time() try: server.start() server.wait() t_end = time.time() except KeyboardInterrupt: t_end = time.time() server.stop() print('*** Stats ***') msgs_per_sec = float(control._counter) / float(t_end - t_start) print('msgs/sec:\t%.2f' % (msgs_per_sec, )) print('msgs:\t%d' % control._counter) print('secs:\t%d' % (t_end - t_start, )) LOG.info("Exciting...")
def main(argv=None): opts = setup_options(argv) core.setup_logging(level=logging.WARN if opts.quiet else logging.DEBUG) if core.forkme_and_wait(opts.processes): # I'm the father and I'm done sys.exit(0) transport_url = core.rabbit_connection_url(driver='rabbit') transport = messaging.get_transport(cfg.CONF, transport_url) t = TestClient(transport) ctxt = {'a': 1} i = 0 errors = 0 try: while opts.num_messages == 0 or i < opts.num_messages: if opts.no_uuid: arg = opts.message else: arg = opts.message + str(uuid.uuid4()) LOG.debug("Requesting echo(%s)" % arg) try: response = t.echo(ctxt, arg) LOG.info("Got %r" % (response,)) assert arg == response, "%s != %s" % (arg, response) i += 1 except messaging.exceptions.MessagingTimeout as ex: LOG.warn('Received MessagingTimeout exception: %s' % str(ex)) errors += 1 if opts.publish_interval > 0: time.sleep(opts.publish_interval) if not opts.reuse_transport: renew = True if opts.renew_transport > 0 and i % opts.renew_transport != 0: renew = False if renew: if opts.transport_cleanup: # removes the reply_* queue associated with this # transport t._client.transport.cleanup() transport = messaging.get_transport(cfg.CONF, transport_url) t = TestClient(transport) except KeyboardInterrupt: # TODO: clean connections and asdf sys.exit(0)
def main(): args = setup_options() core.setup_logging(level=logging.WARN if args.quiet else logging.DEBUG) consumer = MyConsumer(core.rabbit_connection_url()) consumer.routing_key = args.routing_key consumer.num_msgs_acked = args.num_messages try: consumer.run() except KeyboardInterrupt: consumer.stop()
def main(argv=None): args = setup_options() i = 0 pids = [] child = False while True: pid = os.fork() if pid == 0: LOG.debug('breaking') child = True break pids.append(pid) i += 1 if i >= args.processes: break if not child: # wait until childs exit while len(pids) > 0: i = 0 while i < len(pids): pid = pids[i] try: os.waitpid(pid, 0) i += 1 except OSError: pids.remove(pid) sys.exit(0) core.setup_logging(level=logging.WARN if args.quiet else logging.DEBUG) example = ExamplePublisher(core.rabbit_connection_url()) example.publish_interval = args.publish_interval example.message = args.message example.msg_content_type = args.message_type example.num_messages = args.num_messages example.routing_key = "example.%s" % os.getpid() if args.message_type == 'json': example.content_type = 'application/json' else: example.content_type = 'text/plain' try: example.run() except KeyboardInterrupt: example.stop() sys.exit(0)