How to use the pika.URLParameters function in pika

To help you get started, we’ve selected a few pika 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 ManageIQ / integration_tests / cfme / utils / dockerbot / check_prs.py View on Github external
def send_message_to_bot(msg):

    required_fields = {'rabbitmq_url', 'gh_queue', 'gh_channel', 'gh_message_type'}
    if not required_fields.issubset(docker_conf.keys()):
        logger.warning(f"Skipping - docker.yaml doesn't have {required_fields}")
        return

    logger.info(f"Github PR bot: about to send '{msg}'")
    url = docker_conf['rabbitmq_url']
    queue = docker_conf['gh_queue']
    irc_channel = docker_conf['gh_channel']
#    message_type = docker_conf['gh_message_type']
    params = pika.URLParameters(url)
    params.socket_timeout = 5
    connection = None
    try:
        connection = pika.BlockingConnection(params)  # Connect to CloudAMQP
        channel = connection.channel()
        message = {"channel": irc_channel, "body": msg}
        channel.basic_publish(exchange='', routing_key=queue,
                              body=json.dumps(message, ensure_ascii=True))
    except Exception:
        output = traceback.format_exc()
        logger.warning(f"Exception while sending a message to the bot: {output}")
    finally:
        if connection:
            connection.close()
github RD17 / ambar / Pipeline / pipeline.py View on Github external
pstProcessor = PstProcessor(logger, apiProxy)
# instantiating Parser
fileParser = FileParser(logger, PARSE_TIMEOUT_SECONDS, ocrPdfSymbolsPerPageThreshold, ocrPdfMaxPageCount)
# instantiating AutoTagger
autoTagger = AutoTagger(logger, apiProxy)
# checking whether to preserve originals or not
preserveOriginals = True if preserveOriginals else False

# reporting start
logger.LogMessage('info', 'started')

# connecting to Rabbit
logger.LogMessage('info', 'connecting to Rabbit {0}...'.format(rabbitHost))

try:
    rabbitConnection = pika.BlockingConnection(pika.URLParameters(
        '{0}?heartbeat={1}'.format(rabbitHost, RABBIT_HEARTBEAT)))
    rabbitChannel = rabbitConnection.channel()
    rabbitChannel.basic_qos(prefetch_count=1, all_channels=True)
    logger.LogMessage('info', 'connected to Rabbit!')
except Exception as e:
    logger.LogMessage('error', 'error initializing connection to Rabbit {0}'.format(repr(e)))
    exit(1)

# starting pipeline
logger.LogMessage('info', 'waiting for messages...')


def ProcessFile(message):
    try:
        meta = message['meta']
        event = message['event']
github pika / pika / examples / send.py View on Github external
import pika
import time
import logging

logging.basicConfig(level=logging.DEBUG)

ITERATIONS = 100

connection = pika.BlockingConnection(pika.URLParameters('amqp://guest:guest@localhost:5672/%2F?heartbeat_interval=1'))
channel = connection.channel()

def closeit():
    print('Close it')
    connection.close()

connection.call_later(5, closeit)

connection.sleep(100)

"""
channel.confirm_delivery()
github ansible / ansible / lib / ansible / module_utils / rabbitmq.py View on Github external
def connect_to_rabbitmq(self):
        """
        Function to connect to rabbitmq using username and password
        """
        try:
            parameters = pika.URLParameters(self.url)
        except Exception as e:
            self.module.fail_json(msg="URL malformed: %s" % to_native(e))

        try:
            self.connection = pika.BlockingConnection(parameters)
        except Exception as e:
            self.module.fail_json(msg="Connection issue: %s" % to_native(e))

        try:
            self.conn_channel = self.connection.channel()
        except pika.exceptions.AMQPChannelError as e:
            self.close_connection()
            self.module.fail_json(msg="Channel issue: %s" % to_native(e))
github metaspace2020 / metaspace / metaspace / engine / sm / engine / queue.py View on Github external
def connect(self):
        """This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.

        :rtype: pika.SelectConnection

        """
        self.logger.info('Connecting to %s', self._url)
        return pika.SelectConnection(
            pika.URLParameters(self._url), self.on_connection_open, stop_ioloop_on_close=False
        )
github dturanski / python-spring-cloud-stream / examples / cloudfoundry / spring_cloud_stream_sink_cloudfoundry / consumer.py View on Github external
'''Dump the environment just for fun'''
for (k,v) in env.iteritems():
    print ("{0}={1}".format(k,v))

connection = None

app = cf.App(env)

'''start a thread to listen on the health check endpoint. Another option is to disable health checks'''
health_check = app.start_health_check()

try:

    '''Get service info from VCAP_SERVICES'''
    connectionUrl = app.service('rabbit')['credentials']['uri']
    connection = pika.BlockingConnection(pika.URLParameters(connectionUrl))

    sink = components.Sink()
    sink.bind(Binder(connection, env))

    def callback(channel, method, properties, body):
      print(" [x] Received %r" % body, properties)

    print "Listening for messages..."

    sink.receive(callback)
finally:
    if (connection) :
        connection.close()
    health_check.terminate()
github studioml / studio / studio / rabbit_queue.py View on Github external
def connect(self):
        """
        When the connection is established, the on_connection_open method
        will be invoked by pika. If you want the reconnection to work, make
        sure you set stop_ioloop_on_close to False, which is not the default
        behavior of this adapter.

        :rtype: pika.SelectConnection

        """
        return pika.SelectConnection(
            pika.URLParameters(
                self._url),
            on_open_callback=self.on_connection_open,
            on_close_callback=self.on_connection_closed,
            stop_ioloop_on_close=False)
github Vanlightly / RabbitMq-PoC-Code / ConsistentHashing / RabbitMqSummit / python / client / send-sequence.py View on Github external
def connect():
    global connection, curr_node, terminate
    print("Attempting to connect to " + nodes[curr_node])
    parameters = pika.URLParameters('amqp://jack:jack@' + nodes[curr_node] + ':5672/%2F')
    connection = pika.SelectConnection(parameters=parameters,
                                on_open_callback=on_open,
                                on_open_error_callback=reconnect,
                                on_close_callback=on_close)

    try:
        connection.ioloop.start()
    except KeyboardInterrupt:
        connection.close()
        connection.ioloop.stop()
        terminate = True
    except Exception as ex:
        template = "An exception of type {0} occurred. Arguments:{1!r}"
        message = template.format(type(ex).__name__, ex.args)
        print(message)
github misspink1011 / News-Manager / common / cloudAMQP_client.py View on Github external
def __init__(self, cloudAMQP_url, queue_name):
        self.cloudAMQP_url = cloudAMQP_url
        self.queue_name = queue_name
        self.params = pika.URLParameters(cloudAMQP_url)
        self.params.socket_timeout = 3
        self.connection = pika.BlockingConnection(self.params)
        self.channel = self.connection.channel()
        self.channel.queue_declare(queue=queue_name)
github AlecAivazis / graphql-over-kafka / nautilus / network / amqp / consumers / amqp.py View on Github external
def connect(self):
        """This method connects to RabbitMQ, returning the connection handle.
        When the connection is established, the on_connection_open method
        will be invoked by pika.

        :rtype: pika.SelectConnection

        """
        LOGGER.info('Connecting to %s', self._url)
        return adapters.TornadoConnection(pika.URLParameters(self._url),
                                          self.on_connection_open)