def connect(self):
     from amqplib.client_0_8.connection import Connection
     try:
         conn = Connection(
             host="%s:%s" % (self.host, self.port),
             userid=self.user,
             password=self.passwd,
             virtual_host=self.vhost,
             ssl=self.ssl
             )
         channel = conn.channel()
     except Exception as e:
         return dict(success=False, msg=str(e))
     return dict(connection=conn, channel=channel, success=True)
def main():
    parser = OptionParser(usage=usage())
    options, args = parser.parse_args()

    if not args:
        print "No queues specified"
        parser.print_usage()
        sys.exit(1)

    # Nested import/functions to prevent unnecessary overhead when no
    # queues are specified
    import Globals
    from Products.ZenUtils.GlobalConfig import getGlobalConfiguration
    global_conf = getGlobalConfiguration()
    hostname = global_conf.get('amqphost', 'localhost')
    port = global_conf.get('amqpport', '5672')
    username = global_conf.get('amqpuser', 'zenoss')
    password = global_conf.get('amqppassword', 'zenoss')
    vhost = global_conf.get('amqpvhost', '/zenoss')
    ssl = global_conf.get('amqpusessl', '0')
    use_ssl = True if ssl in ('1', 'True', 'true') else False

    cxn = Connection(host="%s:%s" % (hostname, port),
                     userid=username,
                     password=password,
                     virtual_host=vhost,
                     ssl=use_ssl)

    with closing(cxn) as conn, closing(conn.channel()) as channel:
        for queue in args:
            print "Removing queue: %s" % queue
            try:
                channel.queue_delete(queue)
            except Exception as e:
                print "ERROR: Unable to remove %s; does it exist?" % queue
                sys.exit(1)
Exemple #3
0
#!/usr/bin/env python

#import amqplib.client_0_8
from amqplib.client_0_8.connection import Connection
from amqplib.client_0_8 import Message
import sys

USER="******"
PWD="bar"
QUEUE_NAME="rainycloud"

if __name__ == '__main__':

    connection = Connection('localhost', USER, PWD)
    
    ch = connection.channel()
    ch.queue_declare(queue=QUEUE_NAME, durable=False)
    ch.queue_bind(queue=QUEUE_NAME, exchange='', routing_key=QUEUE_NAME)

    count = -1
    if len(sys.argv) > 2:
        count = int(sys.argv[2])

    for row in open("ranges"):
        if(count == 0):
            break

        count -= 1

        size, start = row.strip().split()
        msg = '{"task": "%s", "start": "%s:", "size": %s, "retries": 1 }' % (sys.argv[1], start, int(size))
Exemple #4
0
 def getConnection(self):
     settings = self.getConnectionSettings()
     return Connection(**settings)
Exemple #5
0
#!/usr/bin/env python

#import amqplib.client_0_8
from amqplib.client_0_8.connection import Connection
from amqplib.client_0_8 import Message
import sys



if __name__ == '__main__':
    args = []
    if len(sys.argv) > 2:
        args = "[" + ",".join(sys.argv[2:]) + "]"

    start = "12345"
    size = 123

    msg = '{"task": "%s", "start": "%s:", "size": %s, "retries": 0 }' % (sys.argv[1], start, int(size))

    connection = Connection('localhost', 'foo', 'bar')
    
    ch = connection.channel()

    ch.basic_publish(Message(msg), "pippo")