Esempio n. 1
0
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.add_option('-I', '--immediate', dest='immediate',
                      help="Publish message with immediate 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,
                            immediate=options.immediate)
    if not published:
        sys.exit(1)
Esempio n. 2
0
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()
Esempio n. 3
0
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)
Esempio n. 4
0
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()
Esempio n. 5
0
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)
Esempio n. 6
0
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)