How to use the pika.connection.ConnectionParameters 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 pika / pika / tests / unit / connection_parameters_tests.py View on Github external
def test_default_property_values(self):
        self.assert_default_parameter_values(connection.ConnectionParameters())
github ooici / pyon / pyon / net / messaging.py View on Github external
def make_node(connection_params=None, name=None, timeout=None):
    """
    Blocking construction and connection of node.

    @param connection_params  AMQP connection parameters. By default, uses CFG.server.amqp (most common use).
    """
    log.debug("In make_node")
    node = NodeB()
    connection_params = connection_params or CFG.server.amqp
    credentials = PlainCredentials(connection_params["username"], connection_params["password"])
    conn_parameters = ConnectionParameters(host=connection_params["host"], virtual_host=connection_params["vhost"], port=connection_params["port"], credentials=credentials)
    connection = PyonSelectConnection(conn_parameters , node.on_connection_open)
    ioloop_process = gevent.spawn(ioloop, connection, name=name)
    ioloop_process._glname = "pyon.net AMQP ioloop proc"
    #ioloop_process = gevent.spawn(connection.ioloop.start)
    node.ready.wait(timeout=timeout)
    return node, ioloop_process
    #return node, ioloop, connection
github GlobalNOC / OESS / nox / src / nox / netapps / nddi / rmqi.py View on Github external
self.exchange      = kwargs.get('exchange')
        self.topic         = kwargs.get('topic')
        self.queue         = kwargs.get('queue')
        self.exchange_type = 'topic'
        
        if(self.exchange is None):
            print 'Must pass in exchange!'
            sys.exit(1)
        if(self.queue is None):
            print 'Must pass in queue!'
            sys.exit(1)
        if(self.topic is None):
            print 'Must pass in topic!'
            sys.exit(1)

        params = pika.connection.ConnectionParameters(
            host = self.host,
            port = self.port,
            virtual_host = self.virtual_host,
            credentials = pika.credentials.PlainCredentials( username = self.username,
                                                             password = self.password))

        self.connection = pika.BlockingConnection( parameters = params )
        
        self.channel = self.connection.channel()

        self.channel.queue_declare(queue=self.queue,
                                   exclusive=True,
                                   auto_delete=True
                                   )

        self.channel.exchange_declare( exchange = self.exchange,
github python-beaver / python-beaver / beaver / transports / rabbitmq_transport.py View on Github external
def _connect(self):
        credentials = pika.PlainCredentials(
            self._rabbitmq_config['username'],
            self._rabbitmq_config['password']
        )
        ssl_options = {
            'keyfile': self._rabbitmq_config['ssl_key'],
            'certfile': self._rabbitmq_config['ssl_cert'],
            'ca_certs': self._rabbitmq_config['ssl_cacert'],
            'ssl_version': ssl.PROTOCOL_TLSv1
        }
        self._parameters = pika.connection.ConnectionParameters(
            credentials=credentials,
            host=self._rabbitmq_config['host'],
            port=self._rabbitmq_config['port'],
            ssl=self._rabbitmq_config['ssl'],
            ssl_options=ssl_options,
            virtual_host=self._rabbitmq_config['vhost'],
            socket_timeout=self._rabbitmq_config['timeout']
        )
        self._thread = Thread(target=self._connection_start)
        self._thread.start()
github radical-cybertools / radical.entk / src / radical / entk / appman / appmanager.py View on Github external
else               : return val2

        self._hostname         = _if(hostname,        config['hostname'])
        self._port             = _if(port,            config['port'])
        self._username         = _if(username,        config['username'])
        self._password         = _if(password,        config['password'])
        self._reattempts       = _if(reattempts,      config['reattempts'])
        self._resubmit_failed  = _if(resubmit_failed, config['resubmit_failed'])
        self._autoterminate    = _if(autoterminate,   config['autoterminate'])
        self._write_workflow   = _if(write_workflow,  config['write_workflow'])
        self._rmq_cleanup      = _if(rmq_cleanup,     config['rmq_cleanup'])
        self._rts_config       = _if(rts_config,      config['rts_config'])
        self._rts              = _if(rts,             config['rts'])

        credentials = pika.PlainCredentials(self._username, self._password)
        self._rmq_conn_params = pika.connection.ConnectionParameters(
                                        host=self._hostname,
                                        port=self._port,
                                        credentials=credentials)

        self._num_pending_qs   = config['pending_qs']
        self._num_completed_qs = config['completed_qs']

        if self._rts not in ['radical.pilot', 'mock']:
            raise ValueError('invalid RTS %s' % self._rts)
github gmr / tinman / tinman / clients / rabbitmq.py View on Github external
self._channel = None

        # Set our app_id for publishing messages
        self.app_id = "%s/%s" % (RabbitMQ.DEFAULT_APP_ID, __version__)

        # Set our delivery mode for publishing messages
        self.delivery_mode = RabbitMQ.DEFAULT_DELIVERY_MODE

        # Set our encoding for publishing messages
        self.encoding = RabbitMQ.DEFAULT_ENCODING

        # Create our credentials
        creds = credentials.PlainCredentials(username=user, password=password)

        # Create the connection parameters
        self.params = connection.ConnectionParameters(host=host,
                                                      port=port,
                                                      virtual_host=virtual_host,
                                                      credentials=creds)

        # Create a new connection
        tornado_connection.TornadoConnection(self.params, self._on_connected)
github pika / pika / examples / blocking / demo_get.py View on Github external
Example of the use of basic_get. NOT RECOMMENDED for fast consuming - use
basic_consume instead if at all possible!
"""

import sys
import time

from pika.adapters import BlockingConnection
from pika.connection import ConnectionParameters


if __name__ == '__main__':

    # Connect to RabbitMQ
    host = (len(sys.argv) > 1) and sys.argv[1] or '127.0.0.1'
    connection = BlockingConnection(ConnectionParameters(host))

    # Open the channel
    channel = connection.channel()

    # Declare the queue
    channel.queue_declare(queue="test", durable=True,
                          exclusive=False, auto_delete=False)

    # Initialize our timers and loop until external influence stops us
    while connection.is_open:

        # Call basic get which returns the 3 frame types
        method, header, body = channel.basic_get(queue="test")

        # It can be empty if the queue is empty so don't do anything
        if method.NAME == 'Basic.GetEmpty':
github pika / pika / pika / connection.py View on Github external
set this value higher than `socket_timeout`.
        :param str locale: Set the locale value
        :param int|float|None blocked_connection_timeout: If not None,
            the value is a non-negative timeout, in seconds, for the
            connection to remain blocked (triggered by Connection.Blocked from
            broker); if the timeout expires before connection becomes unblocked,
            the connection will be torn down, triggering the adapter-specific
            mechanism for informing client app about the closed connection:
            passing `ConnectionBlockedTimeout` exception to on_close_callback
            in asynchronous adapters or raising it in `BlockingConnection`.
        :param client_properties: None or dict of client properties used to
            override the fields in the default client properties reported to
            RabbitMQ via `Connection.StartOk` method.
        :param tcp_options: None or a dict of TCP options to set for socket
        """
        super(ConnectionParameters, self).__init__()

        if blocked_connection_timeout is not self._DEFAULT:
            self.blocked_connection_timeout = blocked_connection_timeout

        if channel_max is not self._DEFAULT:
            self.channel_max = channel_max

        if client_properties is not self._DEFAULT:
            self.client_properties = client_properties

        if connection_attempts is not self._DEFAULT:
            self.connection_attempts = connection_attempts

        if credentials is not self._DEFAULT:
            self.credentials = credentials
github pika / pika / examples / demo_send.py View on Github external
body=message,
                              properties=properties)

        print "demo_send: Sent %s" % message

    # Close our connection
    print "demo_send: Closing"
    connection.close()


if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)

    # Connect to RabbitMQ
    host = (len(sys.argv) > 1) and sys.argv[1] or '127.0.0.1'
    connection = SelectConnection(ConnectionParameters(host),
                                  on_connected)
    # Loop until CTRL-C
    try:
        # Start our blocking loop
        connection.ioloop.start()

    except KeyboardInterrupt:

        # Close the connection
        connection.close()

        # Loop until the connection is closed
        connection.ioloop.start()
github pika / pika / examples / demo_ssl_send.py View on Github external
if __name__ == '__main__':
    # Setup empty ssl options
    ssl_options = {}

    # Uncomment this to test client certs, change to your cert paths
    # Uses certs as generated from http://www.rabbitmq.com/ssl.html
    ssl_options = {"ca_certs": "/etc/rabbitmq/new/server/chain.pem",
                   "certfile": "/etc/rabbitmq/new/client/cert.pem",
                   "keyfile": "/etc/rabbitmq/new/client/key.pem",
                   "cert_reqs": CERT_REQUIRED}

    # Connect to RabbitMQ
    host = (len(sys.argv) > 1) and sys.argv[1] or '127.0.0.1'
    parameters = ConnectionParameters(host, 5671,
                                      ssl=True, ssl_options=ssl_options)
    connection = SelectConnection(parameters, on_connected)
    # Loop until CTRL-C
    try:
        # Start our blocking loop
        connection.ioloop.start()

    except KeyboardInterrupt:

        # Close the connection
        connection.close()

        # Loop until the connection is closed
        connection.ioloop.start()