Пример #1
0
def rawTaskPublisher(task, args, queue,
                    broker = cfg.RABBITMQ_IP,
                    vhost = cfg.CB_CLUSTER_TAG,
                    exchange = "",
                    userid="guest",
                    password="******",
                    routing_key = None):

    # setup broker connection
    connection = Connection(host = broker, userid=userid, password=password, virtual_host = vhost)
    channel = connection.channel()

    # construct task body
    body={'retries': 0, 'task': task, 'errbacks': None, 'callbacks': None, 'kwargs': {},
         'eta': None, 'args': args, 'id': 'e7cb7ff5-acd3-4060-8f7e-2ef85f810fe5',
         'expires': None, 'utc': True}
    header = {'exclusive': False, 'name': queue, 'headers': {}, 'durable': True, 'delivery_mode': 2,
              'no_ack': False, 'priority': None, 'alias': None, 'queue_arguments': None,
              'content_encoding': 'binary', 'content_type': 'application/x-python-serialize',
              'binding_arguments': None, 'auto_delete': True}

    # prepare message
    body = pickle.dumps(body)
    message = (body, header)

    if routing_key is None:
        routing_key = queue

    # publish!
    rc = channel.basic_publish(message, exchange = exchange,
                               routing_key = routing_key)
def Connect():
    conn = Connection(host=hostname,
                      port=port,
                      userid=user,
                      password=password,
                      virtual_host=vhost)
    channel = conn.channel()
    channel.exchange_declare(exchange_name, 'topic')

    while True:
        s = r.grp['state']

        for x in s:
            arg_body = """Routing Key[%s] ==================================>
XKRX-CS-KR-000252,13:30:48.023942,7,290.9,123.19,90.82,79.62,937.15
XKRX-CS-KR-000253,13:30:48.024171,7,28.84,93.29,67.13,234.64,149.7
""" % x
            arg_rky = s[x]
            print arg_rky, arg_body
            channel.basic_publish(arg_body.replace("KR", x), exchange_name,
                                  arg_rky)

        time.sleep(5)

    channel.close()
    conn.close()
Пример #3
0
 def setUp(self):
     self.connection = Connection(host='localhost:5672',
                                  userid='guest',
                                  password='******',
                                  virtual_host='/')
     self.channel = self.connection.channel()
     self.TEST_QUEUE = 'pyrabbitmq.testq2'
Пример #4
0
 def setUp(self):
     self.connection = Connection(host="localhost:5672",
                                  userid="guest",
                                  password="******",
                                  virtual_host="/")
     self.channel = self.connection.channel()
     self.TEST_QUEUE = "pyrabbitmq.testq2"
Пример #5
0
 def setUp(self):
     self.connection = Connection(host="localhost:5672",
                                  userid="guest",
                                  password="******",
                                  virtual_host="/")
     self.channel = self.connection.channel()
     self._queue_declare()
Пример #6
0
 def setUp(self):
     self.connection = Connection(host='localhost:5672',
                                  userid='guest',
                                  password='******',
                                  virtual_host='/')
     self.channel = self.connection.channel()
     self._queue_declare()
Пример #7
0
    def _check_connection(cls):
        if not getattr(thread_data, 'rabbitmq_connected', False) \
                and 'oioioi.notifications' in settings.INSTALLED_APPS \
                and NotificationHandler.last_connection_check < \
                time.time() - NotificationHandler.conn_try_interval:
            try:
                o = urlparse(settings.NOTIFICATIONS_RABBITMQ_URL)
                kwargs = {}
                if o.hostname:
                    kwargs['host'] = o.hostname
                if o.port:
                    kwargs['port'] = o.port
                if o.username:
                    kwargs['userid'] = o.username
                if o.password:
                    kwargs['password'] = o.password
                if o.path:
                    kwargs['virtual_host'] = o.path
                thread_data.conn = Connection(**kwargs)

                thread_data.rabbitmq_connected = True
            # pylint: disable=broad-except
            except Exception:
                NotificationHandler.last_connection_check = time.time()
                logger.info("Notifications: Can't connect to RabbitMQ",
                            exc_info=True)
Пример #8
0
    def __init__(self, mq_server = None, virtual_host = cfg.CB_CLUSTER_TAG):

        if mq_server == None:
            mq_server = cfg.RABBITMQ_IP

        self.connection = Connection(host= mq_server, userid="guest", password="******", virtual_host = virtual_host)
        self.manager = Client(mq_server+":55672", "guest", "guest")
Пример #9
0
    def __init__(self, mq_server = None):

        if mq_server == None:
            mq_server = cfg.RABBITMQ_IP

        self.connection = Connection(host= mq_server, userid="guest", password="******", virtual_host="/")
        self.declare("workload")
        self.declare("workload_template")
Пример #10
0
 def _connect(self):
     """Creates our AMQP connection"""
     try:
         self.connection = Connection(host=self.host)
         self.channel = self.connection.channel()
         logging.info('Connected to server: ' + self.host)
         self.last_connect = int(time.time())
         return True
     except ConnectionError:
         logging.error('Unable to connect to server')
         return None
Пример #11
0
 def connect(self):
     connections['default'].close()
     rabbitmq = ALCO_SETTINGS['RABBITMQ']
     self.amqp = Connection(**rabbitmq)
     self.redis = redis.Redis(**ALCO_SETTINGS['REDIS'])
     self.insert_thread = Thread(target=self.inserter_loop)
     self.insert_thread.start()
     hostname = '%s:%s' % (rabbitmq['host'],
                           ALCO_SETTINGS['RABBITMQ_API_PORT'])
     self.rabbit = Client(hostname, rabbitmq['userid'],
                          rabbitmq['password'])
     self.vhost = rabbitmq['virtual_host']
	def run(self):
		self.conn = Connection(host=hostname, port=port, userid=user, password=password, virtual_host=vhost)
		self.channel = self.conn.channel()
		self.channel.exchange_declare(exchange_name, 'topic')
		queueId = self.channel.queue_declare( exclusive = True ).queue
		self.channel.queue_bind(queueId, exchange_name, self.routingKey)
		try:
		    self.channel.basic_consume(queueId, callback=self.callback_rdm)
		except KeyboardInterrupt:
		    self.channel.close()
		    self.conn.close()

		while True:
			self.conn.drain_events()
def start_rabbitmq():
    vhost_present = False
    tries = 1
    print("\n##### Setting up RabbitMQ @ {0} #####".format(cfg.RABBITMQ_IP))
    rabbitmq_client = get_ssh_client(cfg.RABBITMQ_IP)

    _, stdout, _ = rabbitmq_client.exec_command(
        "ps aux|grep rabbitmq|grep -v grep|awk \'{print $2}\'")
    print("Killing existing RabbitMQ process ...")
    for pid in stdout:
        if pid == "":
            continue
        rabbitmq_client.exec_command("sudo kill -9 {0}".format(pid))
    if cfg.RABBITMQ_LOG_LOCATION is not "":
        print("Deleting RabbitMQ logs from {0}".format(
            cfg.RABBITMQ_LOG_LOCATION))
        rabbitmq_client.exec_command("rm -rf {0}/*.*".format(
            cfg.RABBITMQ_LOG_LOCATION))
    print("Starting RabbitMQ ...")
    rabbitmq_client.exec_command(
        "screen -dmS rabbitmq sh -c \'sudo rabbitmq-server start; exec bash;\'"
    )
    time.sleep(20)
    _, stdout, _ = rabbitmq_client.exec_command("sudo rabbitmqctl status")
    for line in stdout.readlines():
        sys.stdout.write(line)
    print("Rabbitmq has been restarted and is now running!")
    _, stdout, _ = rabbitmq_client.exec_command("sudo rabbitmqctl list_vhosts")
    for line in stdout.readlines():
        if not vhost_present:
            if cfg.CB_CLUSTER_TAG in line:
                vhost_present = True
        sys.stdout.write(line)
    if not vhost_present:
        print("Adding vhost {0} and setting permissions".format(
            cfg.CB_CLUSTER_TAG))
        rabbitmq_client.exec_command("sudo rabbitmqctl add_vhost {0}".format(
            cfg.CB_CLUSTER_TAG))
        rabbitmq_client.exec_command(
            "sudo rabbitmqctl set_permissions -p {0} guest '.*' '.*' '.*'".
            format(cfg.CB_CLUSTER_TAG))
        _, stdout, _ = rabbitmq_client.exec_command(
            "sudo rabbitmqctl list_vhosts")
        for line in stdout.readlines():
            sys.stdout.write(line)
    time.sleep(30)
    while True:
        try:
            tries += 1
            Connection(host=cfg.RABBITMQ_IP,
                       userid="guest",
                       password="******",
                       virtual_host=cfg.CB_CLUSTER_TAG)
            print("Connected to RabbitMQ vhost")
            break
        except Exception as e:
            print e
            if tries <= 5:
                print("Retrying connection {0}/5 ...".format(tries))
                rabbitmq_client.exec_command(
                    "sudo rabbitmqctl delete_vhost {0}".format(
                        cfg.CB_CLUSTER_TAG))
                rabbitmq_client.exec_command(
                    "sudo rabbitmqctl add_vhost {0}".format(
                        cfg.CB_CLUSTER_TAG))
                rabbitmq_client.exec_command(
                    "sudo rabbitmqctl set_permissions -p {0} guest '.*' '.*' '.*'"
                    .format(cfg.CB_CLUSTER_TAG))
                time.sleep(30)
                continue
            sys.exit(1)
    rabbitmq_client.close()
Пример #14
0
 def __init__(self, qn):
     self.queue_name = qn
     self.connection = Connection()
     self.channel = self.connection.channel()
     self.start_matchmaking_queue()
Пример #15
0
# coding=utf-8
import sys

from librabbitmq import Connection

connection = Connection(host='localhost',
                        userid='dongwm',
                        password='******',
                        virtual_host='web_develop')
channel = connection.channel()

channel.exchange_declare('web_develop',
                         'direct',
                         passive=False,
                         durable=True,
                         auto_delete=False)
if len(sys.argv) != 1:
    msg = sys.argv[1]
else:
    msg = 'hah'

channel.basic_publish(msg, 'web_develop', 'xxx_routing_key')

connection.close()
Пример #16
0
    def __init__(self, mq_server = None):

        if mq_server == None:
            mq_server = cfg.RABBITMQ_IP

        self.connection = Connection(host= mq_server, userid="guest", password="******", virtual_host=cfg.CB_CLUSTER_TAG)
 def get_conn(self):
     from librabbitmq import Connection
     return Connection(**self.conn_info)
Пример #18
0
import os

from librabbitmq import Connection

x = Connection()
c = x.channel()
c.exchange_declare('getmem')
c.queue_declare('getmem')
c.queue_bind('getmem', 'getmem', 'getmem')

from time import sleep

for i in xrange(10000):
    c.basic_publish('foo', exchange='getmem', routing_key='getmem')
    if not i % 1000:
        print('sent %s' % i)

for i in xrange(10000):
    assert c.basic_get('getmem', no_ack=True)
    if not i % 1000:
        print(i)
        os.system('sh -c "ps auxww | grep %d | grep -v grep "' % os.getpid())