def setUp(self): # Start a mock server on a random port self.httpd = BaseHTTPServer.HTTPServer(('', 0), MockZepServiceHandler) self.port = self.httpd.socket.getsockname()[1] thread = threading.Thread(target=self.httpd.serve_forever) thread.daemon = True thread.start() # Connect the client to the random port schema = Schema(SCHEMA) self.client = ZepServiceClient('http://localhost:%d' % self.port, schema)
def main(): from optparse import OptionParser import sys parser = OptionParser(usage=usage()) parser.add_option('-F', '--format', type='string', dest='format', default='protostream', help='Format to dump the messages in (%s)' % ', '.join(_FORMATTERS.keys())) parser.add_option( '-c', '--compression', type='string', dest='compression', default='none', help='Message compression algorithm (possible values: deflate, none)') parser = AMQPConfig.addOptionsToParser(parser) parser = addLoggingOptions(parser) options, args = parser.parse_args() schemas = [SCHEMA] schemas.extend(get_zenpack_schemas()) try: formatter = _FORMATTERS[options.format.lower()] except KeyError: parser.error('Invalid format "%s"' % options.format) initLogging(options) amqpConnectionInfo = AMQPConfig() amqpConnectionInfo.update(options) schema = Schema(*schemas) schema.loadProperties( {'exchange.default.compression': options.compression.lower()}) publisher = getProtobufPubSub(amqpConnectionInfo, schema, None) loader = Loader(sys.stdin, formatter, schema, publisher) try: loader.load() except KeyboardInterrupt: pass loader.publisher.shutdown()
}, "$DefaultPropertiesQueue": { "name" : "zenoss.queues.properties", "durable" : true, "exclusive" : false, "auto_delete" : false, "description" : "Propertied queue." } } } """ explicit_properties = { 'exchange.$ExplicitPropertiesExchange.delivery_mode': '1', 'queue.$ExplicitPropertiesQueue.x-message-ttl': '54321', 'queue.$ExplicitPropertiesQueue.x-expires': '11235' } default_properties = { 'exchange.default.delivery_mode': '1', 'exchange.$ExplicitPropertiesExchange.delivery_mode': '2', 'queue.default.x-message-ttl':'54321', 'queue.default.x-expires':'11235', 'queue.$ExplicitPropertiesQueue.x-message-ttl':'12345', 'queue.$ExplicitPropertiesQueue.x-expires':'81321' } from json import loads queueschema = Schema(loads(mock_schema))
def main(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.add_option('-E', '--exchange', type='string', dest='exchange', help="Exchange to push to", action='store') parser.add_option('-T', '--type', type='string', dest='messageType', help="Type of message to create", action='store') parser.add_option('-R', '--routingkey', type='string', dest='routingKey', help="Routing key for message", action='store') parser.add_option('-D', '--data', type='string', dest='data', help="Message data as JSON, use '-' to read from stdin", action='store') parser.add_option('-M', '--mandatory', dest='mandatory', help="Publish message with mandatory flag set.", action='store_true') parser = AMQPConfig.addOptionsToParser(parser) parser = addLoggingOptions(parser) options, args = parser.parse_args() if not options.data: parser.error('You must supply input data.') elif not options.exchange: parser.error('You must supply an exchange.') elif not options.messageType: parser.error('You must supply a message type.') elif not options.routingKey: parser.error('You must supply a routing key.') schemas = [SCHEMA] schemas.extend(get_zenpack_schemas()) amqpConnectionInfo = AMQPConfig() amqpConnectionInfo.update(options) schema = Schema(*schemas) publisher = Publisher(amqpConnectionInfo, schema) initLogging(options) pusher = Pusher(options.exchange, options.messageType, schema, publisher) if options.data == '-': data = loads(sys.stdin.read()) else: data = loads(options.data) published = pusher.push(data=data, routingKey=options.routingKey, mandatory=options.mandatory) if not published: sys.exit(1)
def _loadZenossQueueSchemas(): schemas = [SCHEMA] # Load the compiled schema schemas.extend(_getZenPackSchemas()) schema = Schema(*schemas) schema.loadProperties(_parseMessagingConf()) return schema
def main(): from optparse import OptionParser import sys parser = OptionParser(usage=usage()) parser.add_option( "-A", '--ack', action="store_true", dest="acknowledge", help= "Acknowledge the message, acknowledging a message will remove it from the queue" ) parser.add_option('-F', '--format', type='string', dest='format', default='json', help='Format to dump the messages in (%s)' % ', '.join(_FORMATTERS.keys())) parser.add_option('-M', '--max', type='int', dest='max_items', help='Maximum items to dump') parser.add_option( '-S', '--skip', action="store_true", dest="skip", help= "Skip processing messages on the queue - use with --ack to clear a queue." ) parser = AMQPConfig.addOptionsToParser(parser) parser = addLoggingOptions(parser) options, args = parser.parse_args() if not args: parser.error("Require one or more queues as arguments") if options.skip and not options.acknowledge: parser.error("Option --skip must be used with --ack") schemas = [SCHEMA] schemas.extend(get_zenpack_schemas()) amqpConnectionInfo = AMQPConfig() amqpConnectionInfo.update(options) schema = Schema(*schemas) try: formatter = _FORMATTERS[options.format.lower()] except KeyError: parser.error('Invalid format "%s"' % options.format) initLogging(options) publisher = Publisher(amqpConnectionInfo, schema) dumper = Dumper(sys.stdout, formatter, publisher.getChannel(), schema, acknowledge=options.acknowledge, skip=options.skip) dumper.dumpQueues(args, limit=options.max_items)