當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。