当前位置: 首页>>代码示例>>Python>>正文


Python Connection.establish方法代码示例

本文整理汇总了Python中qpid.messaging.Connection.establish方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.establish方法的具体用法?Python Connection.establish怎么用?Python Connection.establish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qpid.messaging.Connection的用法示例。


在下文中一共展示了Connection.establish方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checkAuth

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    def checkAuth(self, user, password):
        """
        This function checks a username / password combination using
        the AMQP service' SASL configuration.

        =============== ============
        Parameter       Description
        =============== ============
        user            Username
        password        Password
        =============== ============

        ``Return:`` Bool, success or failure
        """
        # Strip username/password parts of url
        url = "%s:%s" % (self.url['host'], self.url['port'])

        # Don't allow blank authentication
        if user == "" or password == "":
            return False

        try:
            conn = Connection.establish(url, transport=self.url['transport'], username=user, password=password)
            conn.close()
        except ConnectionError as e:
            self.log.debug("AMQP service authentication reports: %s" % str(e))
            return False
        except Exception as e:
            self.log.critical("cannot proceed with authentication")
            self.log.exception(e)
            return False

        return True
开发者ID:gonicus,项目名称:clacks,代码行数:35,代码来源:amqp.py

示例2: start

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    def start(self):
        """
        Enable AMQP queueing. This method puts up the event processor and
        sets it to "active".
        """
        self.log.debug("enabling AMQP queueing")

        # Evaluate username
        user = self.env.config.get("amqp.id", default=None)
        if not user:
            user = self.env.uuid

        # Create initial broker connection
        url = "%s:%s" % (self.url['host'], self.url['port'])
        self._conn = Connection.establish(url, reconnect=self.reconnect,
            username=user,
            password=self.env.config.get("amqp.key"),
            transport=self.url['transport'],
            reconnect_interval=self.reconnect_interval,
            reconnect_limit=self.reconnect_limit)

        # Do automatic broker failover if requested
        if self.env.config.get('amqp.failover', default=False):
            auto_fetch_reconnect_urls(self._conn)

        # Create event provider
        self._eventProvider = EventProvider(self.env, self._conn)
开发者ID:lhm-limux,项目名称:gosa,代码行数:29,代码来源:amqp.py

示例3: __init__

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
 def __init__(self, url, receiver_name, sender_name='pulp.task', asserting=False, **options):
     '''establishes a connection to given url; initializes session, sender and receiver'''
     self.url = url
     self.receiver_name = receiver_name
     self.sender_name = sender_name
     self._asserting = asserting
     self.last_sent = None
     self.last_fetched = None
     self.session = Connection.establish(self.url, **options).session()
     self.receiver = self.session.receiver("%s; {create: always}" % self.receiver_name)
     self.sender = self.session.sender(self.sender_name)
     self._timeout = None
开发者ID:alexxa,项目名称:pulp-automation,代码行数:14,代码来源:qpid_handle.py

示例4: __init__

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    def __init__(self, url, domain="org.clacks", xquery=".", callback=None):

        # Build connection
        url = parseURL(url)

        _url = "%s:%s" % (url['host'], url['port'])
        self.__conn = Connection.establish(_url, reconnect=True,
            username=url['user'],
            password=url['password'],
            transport=url['transport'],
            reconnect_interval=3,
            reconnect_limit=0)

        # Do automatic broker failover if requested
        #TODO: configure reconnect
        #auto_fetch_reconnect_urls(self.__conn)

        # Assemble subscription query
        queue = 'event-listener-%s' % uuid4()
        address = """%s; {
            create: always,
            delete:always,
            node: {
                durable: False,
                x-declare: {
                    exclusive: True,
                    auto-delete: True }
            },
            link: {
                x-bindings: [
                        {
                            exchange: '%s',
                            queue: %s,
                            key: event,
                            arguments: { xquery: %r}
                        }
                    ]
                }
            }""" % (queue, domain, queue, xquery)

        # Add processor for core.event queue
        self.__callback = callback
        self.__eventWorker = AMQPStandaloneWorker(
                        self.__conn,
                        r_address=address,
                        workers=1,
                        callback=self.__eventProcessor)
开发者ID:gonicus,项目名称:clacks,代码行数:49,代码来源:amqp_proxy.py

示例5: start

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    def start(self):
        """
        Enable AMQP queueing. This method puts up the event processor and
        sets it to "active".
        """
        self.log.debug("enabling AMQP queueing")

        # Evaluate username
        user = self.config.get("amqp.id", default=None)
        if not user:
            user = self.env.uuid
        password = self.config.get("amqp.key")

        # Create initial broker connection
        url = "%s:%s" % (self.url['host'], self.url['port'])
        self._conn = Connection.establish(url, reconnect=self.reconnect,
            username=user,
            password=password,
            transport=self.url['transport'],
            reconnect_interval=self.reconnect_interval,
            reconnect_limit=self.reconnect_limit)

        # Do automatic broker failover if requested
        if self.config.get('amqp.failover', False):
            auto_fetch_reconnect_urls(self._conn)

        # Create event exchange
        socket = connect(self.url['host'], self.url['port'])
        if self.url['scheme'][-1] == 's':
            socket = ssl(socket)
        user = self.config.get("amqp.id", default=None)
        if not user:
            user = self.env.uuid
        connection = DirectConnection(sock=socket,
                username=user,
                password=self.config.get("amqp.key"))
        connection.start()
        session = connection.session(str(uuid4()))
        # pylint: disable=E1103
        session.exchange_declare(exchange=self.env.domain, type="xml")
        connection.close()

        # Create event provider
        self._eventProvider = EventProvider(self.env, self.getConnection())
开发者ID:lhm-limux,项目名称:gosa,代码行数:46,代码来源:amqp.py

示例6: get_args

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]

def get_args():
    parser = argparse.ArgumentParser(description="print messages sent to a qpid exchange")
    parser.add_argument("-e", "--exchange", help="name of a qpid exchange (default: amq.topic)", default="amq.topic")
    parser.add_argument("-s", "--subject", help="message subject to bind to", required=False)
    parser.add_argument("-a", "--address", help="hostname to connect to (default:localhost)", default="localhost")
    parser.add_argument("-p", "--port", help="port to connect to (default: 5672)", default="5672")
    parser.add_argument("-q", "--quiet", help="show message subject only", default=False, action="store_true")
    return parser.parse_args()


args = get_args()

source = args.exchange
if args.subject:
    source = "%s/%s" % (source, args.subject)

receiver = Connection.establish("%s:%s" % (args.address, args.port)).session().receiver(source)

try:
    while True:
        message = receiver.fetch()
        if args.quiet:
            print message.subject
        else:
            print "------------------"
            print message
except KeyboardInterrupt:
    print ""
开发者ID:credativ,项目名称:pulp,代码行数:31,代码来源:listen.py

示例7: get

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    consumers = get('/consumers/')
    return [ c['id'] for c in consumers if c['notes'].get('_child-node', False) ]


def get_nodes_repos(node):
    " Returns a child node's 'bound' repos."
    bindings = get("/consumers/%s/bindings/" % (node))
    return [ repo['repo_id'] for repo in bindings ]


if __name__ == '__main__':
    args = get_args()

    # qpid connection
    address = "%s:%s" % (args.host, args.port)
    receiver = Connection.establish(address).session().receiver(args.exchange)

    try:
        while True:
            message = receiver.fetch()
            json_message = json.loads(message.content)

            if json_message['payload']['result'] == 'success':
                repo_id = json_message['payload']['repo_id']
            else:
                continue

            nodes = get_nodes()
            for node in nodes:
                repos = get_nodes_repos(node)
                if repo_id in repos:
开发者ID:galkindmitrii,项目名称:pulp_node_sync,代码行数:33,代码来源:pulp_node_sync.py

示例8: SetBroker

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
 def SetBroker(self, brokerUrl):
     self.url = brokerUrl
     self.connection = Connection.establish(self.url, **conn_options)
     self.broker = BrokerAgent(self.connection)
开发者ID:noelo,项目名称:qpid-stat-json,代码行数:6,代码来源:mrg_m_query.py

示例9: __init__

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
 def __init__(self, address, **kwargs):
     self._connection = Connection.establish(
         address, client_properties={"qpid.ha-admin":1}, **kwargs)
     self._agent = BrokerAgent(self._connection)
     assert self._agent.getHaBroker(), "HA module not loaded in broker at: %s"%(address)
开发者ID:cajus,项目名称:qpid-cpp-debian,代码行数:7,代码来源:ha_tests.py

示例10: exit

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
    from mock import MagicMock
    from mock import patch
except ImportError:
    print 'Cannot run test without python MagicMock'
    print 'Please install MagicMock: pip install mock'
    exit(3)

connection = None
broker = None

try:
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
    logger = logging.getLogger(__name__)

    # setup broker connection
    connection = Connection.establish('127.0.0.1')
    broker = BrokerAgent(connection)

    # add test service busname
    busname = 'test-lofarbus-%s' % (uuid.uuid1())
    broker.addExchange('topic', busname)

    # the system under test is the service and the rpc, not the RADatabase
    # so, patch (mock) the RADatabase class during these tests.
    # when the service instantiates an RADatabase it will get the mocked class.
    with patch('lofar.sas.resourceassignment.database.radb.RADatabase', autospec=True) as MockRADatabase:
        mock = MockRADatabase.return_value
        # modify the return values of the various RADatabase methods with pre-cooked answers
        mock.getTaskStatuses.return_value = [{'id': 1, 'name': 'opened'}, {'id': 2, 'name': 'scheduled'}]
        mock.getTaskTypes.return_value = [{'id': 0, 'name': 'OBSERVATION'}, {'id': 1, 'name': 'PIPELINE'}]
        mock.getResourceClaimStatuses.return_value = [{'id': 0, 'name': 'CLAIMED'},{'id': 1, 'name': 'ALLOCATED'},{'id': 2, 'name': 'CONFLICT'}]
开发者ID:jjdmol,项目名称:LOFAR,代码行数:33,代码来源:test_ra_service_and_rpc.py

示例11: __init__

# 需要导入模块: from qpid.messaging import Connection [as 别名]
# 或者: from qpid.messaging.Connection import establish [as 别名]
 def __init__(self, address, **kwargs):
     self._connection = Connection.establish(
         address, client_properties={"qpid.ha-admin":1}, **kwargs)
     self._agent = BrokerAgent(self._connection)
开发者ID:ncdc,项目名称:qpid,代码行数:6,代码来源:ha_test.py


注:本文中的qpid.messaging.Connection.establish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。