def get_manager(client, hostname=None, port=None, userid=None, password=None): import pyrabbit opt = client.transport_options.get host = (hostname if hostname is not None else opt( 'manager_hostname', client.hostname or 'localhost')) port = port if port is not None else opt('manager_port', 55672) return pyrabbit.Client( '%s:%s' % (host, port), userid if userid is not None else opt( 'manager_userid', client.userid or 'guest'), password if password is not None else opt('manager_password', client.password or 'guest'))
def get_manager(self, hostname=None, port=None, userid=None, password=None): import pyrabbit c = self.client opt = c.transport_options.get host = (hostname if hostname is not None else opt("manager_hostname", c.hostname)) port = port if port is not None else opt("manager_port", 55672) return pyrabbit.Client("%s:%s" % (host, port), userid if userid is not None else opt("manager_userid", c.userid), password if password is not None else opt("manager_password", c.password))
def get_manager(client, hostname=None, port=None, userid=None, password=None): import pyrabbit opt = client.transport_options.get def get(name, val, default): return (val if val is not None else opt('manager_%s' % name) or getattr(client, name, None) or default) host = get('hostname', hostname, 'localhost') port = port if port is not None else opt('manager_port', 15672) userid = get('userid', userid, 'guest') password = get('password', password, 'guest') return pyrabbit.Client('%s:%s' % (host, port), userid, password)
def _configure(self): connection = pika.BlockingConnection( pika.ConnectionParameters(host=self._host, port=self._port, heartbeat_interval=20, credentials=pika.PlainCredentials( username=self._username, password=self._password))) channel = connection.channel() self._connection = connection self._channel = channel self._api_client = pyrabbit.Client( "{host}:15672".format(host=self._host), self._username, self._password)
def get_manager(client, hostname=None, port=None, userid=None, password=None): """Get pyrabbit manager.""" import pyrabbit opt = client.transport_options.get def get(name, val, default): return ( val if val is not None else opt("manager_%s" % name) or getattr(client, name, None) or default ) host = get("hostname", hostname, "localhost") port = port if port is not None else opt("manager_port", 15672) userid = get("userid", userid, "guest") password = get("password", password, "guest") return pyrabbit.Client("%s:%s" % (host, port), userid, password)
# necessary because pyrabbit prints crap to the output # pull-requested a change: # https://github.com/istepaniuk/pyrabbit/commit/41c9a11245475729f114ecc3dcfa20a4f5409545 import redirect parser = argparse.ArgumentParser( description='Gets messages from a queue. Does not requeue!') parser.add_argument('queue_name', metavar='ORIGINAL_QUEUE_NAME', type=str, help='the name the queue to get messages from') args = parser.parse_args() parsed_url = urlparse.urlparse(settings.RABBITMQ_BROKER_URL) client = pyrabbit.Client(parsed_url.hostname + ":" + str(parsed_url.port), parsed_url.username, parsed_url.password) with redirect.RedirectStdStreamsToDevNull(): messages = client.get_messages('/', args.queue_name, 1000, requeue=False) def set_output_encoding(encoding='utf-8'): import sys import codecs '''When piping to the terminal, python knows the encoding needed, and sets it automatically. But when piping to another program (for example, | less), python can not check the output encoding. In that case, it is None. What I am doing here is to catch this situation for both stdout and stderr and force the encoding''' current = sys.stdout.encoding if current is None:
username, password = things[0].split(':', 1) host_and_port = things[1] else: username, password = '******', 'guest' if not vhost: vhost = '/' host_and_port = host_and_port.replace(':5672', ':15672') return [host_and_port, username, password, vhost] if settings.BROKER_URL.lower().startswith('amqp://'): rabbitmq_params = get_rabbitmq_client_args_from_broker_url() rabbitmq_client = pyrabbit.Client(*rabbitmq_params[:-1]) try: rabbitmq_client.is_alive() except PermissionError: pass except: rabbitmq_params[0] = rabbitmq_params[0].replace(':15672', ':55672') rabbitmq_client = pyrabbit.Client(*rabbitmq_params[:-1]) try: rabbitmq_client.is_alive() except PermissionError: