How to use the amqp.connection function in amqp

To help you get started, we’ve selected a few amqp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PaloAltoNetworks / minemeld-core / minemeld / comm / amqp.py View on Github external
def start(self, start_dispatching=True):
        num_sub_connections = min(self.num_connections, len(self.sub_channels))
        num_conns_total = sum([
            num_sub_connections,
            len(self.rpc_fanout_clients_channels),
            len(self.pub_channels),
            1
        ])

        for j in xrange(num_conns_total):
            self.amqp_config['on_blocked'] = self._blocked
            self.amqp_config['on_unblocked'] = self._unblocked
            c = amqp.connection.Connection(**self.amqp_config)
            c.sock._read_event.priority = self.priority
            c.sock._write_event.priority = self.priority
            self._connections.append(c)

        csel = 0
        for sc in self.sub_channels.values():
            sc.connect(self._connections[csel % num_sub_connections])
            csel += 1

        csel = 0
        for pc in self.pub_channels.values():
            pc.connect(self._connections[num_sub_connections + csel])
            csel += 1

        for rfc in self.rpc_fanout_clients_channels:
            rfc.connect(self._connections[num_sub_connections + csel])
github cr0hn / enteletaor / enteletaor_lib / modules / scan / scan_main.py View on Github external
def handle_amqp(host, port=5672, extra_config=None):

	host_and_port = "%s:%s" % (host, port)

	# log.debug("      * Connection to RabbitMQ: %s : %s" % (host, port))

	try:
		amqp.connection.Connection(host=host_and_port,
		                           connect_timeout=1,
		                           read_timeout=1,
		                           socket_timeout=1)
		return True

	except Exception:
		return False
github lavalamp- / ws-backend-community / lib / deploy.py View on Github external
def __check_for_rabbitmq_availability(self):
        """
        Check to see if the RabbitMQ server is available to run commands against.
        :return: True if the RabbitMQ server is available to run commands against, False otherwise.
        """
        try:
            connection = amqp.connection.Connection(
                host="%s:%s" % (config.celery_host, config.celery_port),
                userid=config.celery_user,
                password=config.celery_password,
                virtual_host=config.celery_virtual_host,
            )
            connection.close()
            return True
        except Exception as e:
            if e not in amqp.exceptions.ERROR_MAP.values():
                raise e
            return False
github PaloAltoNetworks / minemeld-core / minemeld / mgmtbus / amqp.py View on Github external
def __init__(self, config):
        self.fts = []

        self.config = config

        self._connection = amqp.connection.Connection(**self.config)

        self._in_channel = self._connection.channel()
        self._in_channel.exchange_declare(
            AMQP_BUS_EXCHANGE,
            'fanout',
            auto_delete=False
        )
        q = self._in_channel.queue_declare(
            queue=AMQP_PREFIX+str(uuid.uuid4()),
            exclusive=True,
            auto_delete=True
        )
        self._in_channel.queue_bind(
            queue=q.queue,
            exchange=AMQP_BUS_EXCHANGE
        )
github PaloAltoNetworks / minemeld-core / minemeld / ft / syslog.py View on Github external
def _amqp_consumer(self):
        while self.last_ageout_run is None:
            gevent.sleep(1)

        with self.state_lock:
            if self.state != ft_states.STARTED:
                LOG.error('{} - wrong state in amqp_consumer'.format(self.name))
                return

        while True:
            try:
                conn = amqp.connection.Connection(
                    userid=self.rabbitmq_username,
                    password=self.rabbitmq_password
                )
                channel = conn.channel()
                channel.exchange_declare(
                    self.exchange,
                    'fanout',
                    durable=False,
                    auto_delete=False
                )
                q = channel.queue_declare(
                    exclusive=False
                )

                channel.queue_bind(
                    queue=q.queue,
github cr0hn / enteletaor / enteletaor_lib / modules / brute / authers.py View on Github external
def brute_amqp(host, port=5672, user=None, password=None, db=0):

    host_and_port = "%s:%s" % (host, port)
    user_name = "guest" if user is None else user
    user_password = "guest" if password is None else password

    timeout = 0.2
    try:
        amqp.connection.Connection(host=host_and_port,
                                   userid=user_name,
                                   password=user_password,
                                   connect_timeout=timeout,
                                   read_timeout=timeout,
                                   socket_timeout=timeout).connected
        return True
    except socket.timeout as e:
        raise AuthRequired()
    except Exception:
        return False