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


Python BlockingConnection.create_sender方法代码示例

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


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

示例1: test_verify_n_senders

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_verify_n_senders(self):
        n = 2
        addr = self.address()

        # connection should be ok
        denied = False
        try:
            bs1 = BlockingConnection(addr)
        except ConnectionException:
            denied = True

        self.assertFalse(denied) # assert if connections that should open did not open

        # n senders OK
        try:
            s1 = bs1.create_sender(address="****YES_1of2****")
            s2 = bs1.create_sender(address="****YES_2of2****")
        except Exception:
            denied = True

        self.assertFalse(denied) # n senders should have worked

        # receiver n+1 should be denied
        try:
            s3 = bs1.create_sender("****NO****")
        except Exception:
            denied = True

        self.assertTrue(denied) # sender n+1 should have failed

        bs1.close()
开发者ID:ChugR,项目名称:qpid-dispatch,代码行数:33,代码来源:system_tests_policy.py

示例2: test_custom_annotations_match

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_custom_annotations_match(self):
        """
        The linkRoute on Routers C and B is set to org.apache.
        Creates a receiver listening on the address 'org.apache' and a sender that sends to address 'org.apache'.
        Sends a message with custom annotations to org.apache via router QDR.C and makes sure that the message was successfully
        routed (using full address matching) and received using pre-created links that were created as a
        result of specifying addresses in the linkRoute attribute('org.apache.'). Make sure custom annotations arrived as well.
        """
        hello_world_3 = "Hello World_3!"
        # Connects to listener #2 on QDR.C
        addr = self.routers[2].addresses[0]

        blocking_connection = BlockingConnection(addr)

        # Receive on org.apache
        blocking_receiver = blocking_connection.create_receiver(address="org.apache")

        apply_options = AtMostOnce()

        # Sender to  to org.apache
        blocking_sender = blocking_connection.create_sender(address="org.apache", options=apply_options)
        msg = Message(body=hello_world_3)
        annotations = {'custom-annotation': '1/Custom_Annotation'}
        msg.annotations = annotations

        # Send a message
        blocking_sender.send(msg)

        received_message = blocking_receiver.receive()

        self.assertEqual(hello_world_3, received_message.body)
        self.assertEqual(received_message.annotations, annotations)

        blocking_connection.close()
开发者ID:scholzj,项目名称:qpid-dispatch,代码行数:36,代码来源:system_tests_link_routes.py

示例3: test_message_user_id_proxy_zzz_credit_handled

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_message_user_id_proxy_zzz_credit_handled(self):
        # Test for DISPATCH-519. Make sure the REJECTED messages result
        # in the client receiving credit.
        credit_limit = 250   # router issues 250 credits
        ssl_opts = dict()
        ssl_opts['ssl-trustfile'] = self.ssl_file('ca-certificate.pem')
        ssl_opts['ssl-certificate'] = self.ssl_file('client-certificate.pem')
        ssl_opts['ssl-key'] = self.ssl_file('client-private-key.pem')
        ssl_opts['ssl-password'] = 'client-password'

        # create the SSL domain object
        domain = self.create_ssl_domain(ssl_opts)

        # Send a message with bad user_id. This message should be rejected.
        # Connection has user_id 'user13'.
        addr = self.address(13).replace("amqp", "amqps")
        blocking_connection = BlockingConnection(addr, ssl_domain=domain)
        blocking_sender = blocking_connection.create_sender("$management")

        request = proton.Message()
        request.user_id = u"bad-user-id"

        for i in range(0, credit_limit+1):
            result = Delivery.ACCEPTED
            try:
                delivery = blocking_sender.send(request, timeout=10)
                result = delivery.remote_state
            except proton.utils.SendException as e:
                result = e.state
            except proton.utils.Timeout as e:
                self.assertTrue(False, "Timed out waiting for send credit")

            self.assertTrue(result == Delivery.REJECTED,
                            "Router accepted a message with user_id that did not match connection user_id")
开发者ID:ChugR,项目名称:qpid-dispatch,代码行数:36,代码来源:system_tests_user_id_proxy.py

示例4: test_message_user_id_proxy_bad_name_disallowed

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_message_user_id_proxy_bad_name_disallowed(self):
        ssl_opts = dict()
        ssl_opts['ssl-trustfile'] = self.ssl_file('ca-certificate.pem')
        ssl_opts['ssl-certificate'] = self.ssl_file('client-certificate.pem')
        ssl_opts['ssl-key'] = self.ssl_file('client-private-key.pem')
        ssl_opts['ssl-password'] = 'client-password'

        # create the SSL domain object
        domain = self.create_ssl_domain(ssl_opts)

        # Send a message with bad user_id. This message should be rejected.
        # Connection has user_id 'user13'.
        addr = self.address(13).replace("amqp", "amqps")
        blocking_connection = BlockingConnection(addr, ssl_domain=domain)
        blocking_sender = blocking_connection.create_sender("$management")

        request = proton.Message()
        request.user_id = u"bad-user-id"

        result = Delivery.ACCEPTED
        try:
            delivery = blocking_sender.send(request, timeout=10)
            result = delivery.remote_state
        except proton.utils.SendException as e:
            result = e.state

        self.assertTrue (result == Delivery.REJECTED,
                        "Router accepted a message with user_id that did not match connection user_id")
开发者ID:ChugR,项目名称:qpid-dispatch,代码行数:30,代码来源:system_tests_user_id_proxy.py

示例5: test_non_zero_timeout_sender_disallowed

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_non_zero_timeout_sender_disallowed(self):
        addr = self.routers[1].addresses[0]

        connection = BlockingConnection(addr)
        try:
            sender = connection.create_sender(address="org.apache", options=[SenderTimeout(10)])
            self.fail("link should have been detached")
        except LinkDetached:
            pass
        connection.close()
开发者ID:apache,项目名称:qpid-dispatch,代码行数:12,代码来源:system_tests_disallow_link_resumable_link_route.py

示例6: test_expire_never_sender_disallowed

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_expire_never_sender_disallowed(self):
        addr = self.routers[1].addresses[0]

        connection = BlockingConnection(addr)
        try:
            sender = connection.create_sender(address="org.apache", options=[SenderExpiry(Terminus.EXPIRE_NEVER)])
            self.fail("link should have been detached")
        except LinkDetached:
            pass
        connection.close()
开发者ID:apache,项目名称:qpid-dispatch,代码行数:12,代码来源:system_tests_disallow_link_resumable_link_route.py

示例7: test_yy_query_many_links

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_yy_query_many_links(self):
        # This test will fail without the fix for DISPATCH-974
        c = BlockingConnection(self.address())
        count = 0
        links = []
        COUNT = 5000

        ADDRESS_SENDER = "examples-sender"
        ADDRESS_RECEIVER = "examples-receiver"

        # This loop creates 5000 consumer and 5000 producer links with
        # different addresses
        while True:
            count += 1
            r = c.create_receiver(ADDRESS_RECEIVER + str(count))
            links.append(r)
            s = c.create_sender(ADDRESS_SENDER + str(count))
            links.append(c)
            if count == COUNT:
                break

        # Try fetching all 10,000 addresses
        # This qdmanage query command would fail without the fix
        # for DISPATCH-974
        query_command = 'QUERY --type=org.apache.qpid.dispatch.router.address'
        outs = json.loads(self.run_qdmanage(query_command))

        sender_addresses = 0
        receiver_addresses = 0

        for out in outs:
            if ADDRESS_SENDER in out['name']:
                sender_addresses += 1
            if ADDRESS_RECEIVER in out['name']:
                receiver_addresses += 1

        self.assertEqual(sender_addresses, COUNT)
        self.assertEqual(receiver_addresses, COUNT)

        query_command = 'QUERY --type=link'
        outs = json.loads(self.run_qdmanage(query_command))

        out_links = 0
        in_links = 0

        for out in outs:
            if out.get('owningAddr'):
                if ADDRESS_SENDER in out['owningAddr']:
                    in_links += 1
                if ADDRESS_RECEIVER in out['owningAddr']:
                    out_links += 1

        self.assertEqual(out_links, COUNT)
        self.assertEqual(in_links, COUNT)
开发者ID:apache,项目名称:qpid-dispatch,代码行数:56,代码来源:system_tests_qdmanage.py

示例8: test_aaa_partial_link_route_match

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_aaa_partial_link_route_match(self):
        """
        The linkRoutePattern on Routers C and B is set to org.apache.
        Creates a receiver listening on the address 'org.apache.dev' and a sender that sends to address 'org.apache.dev'.
        Sends a message to org.apache.dev via router QDR.C and makes sure that the message was successfully
        routed (using partial address matching) and received using pre-created links that were created as a
        result of specifying addresses in the linkRoutePattern attribute('org.apache.').
        """
        hello_world_1 = "Hello World_1!"

        # Connects to listener #2 on QDR.C
        addr = self.routers[2].addresses[1]

        blocking_connection = BlockingConnection(addr)

        # Receive on org.apache.dev
        blocking_receiver = blocking_connection.create_receiver(address="org.apache.dev")

        apply_options = AtMostOnce()

        # Sender to  to org.apache.dev
        blocking_sender = blocking_connection.create_sender(address="org.apache.dev", options=apply_options)
        msg = Message(body=hello_world_1)
        # Send a message
        blocking_sender.send(msg)

        received_message = blocking_receiver.receive()

        self.assertEqual(hello_world_1, received_message.body)

        # Connect to the router acting like the broker (QDR.A) and check the deliveriesIngress and deliveriesEgress
        local_node = Node.connect(self.routers[0].addresses[0], timeout=TIMEOUT)
        self.assertEqual(u'QDR.A', local_node.query(type='org.apache.qpid.dispatch.router',
                                                    attribute_names=['routerId']).results[0][0])

        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='router.address/M0org.apache.dev').deliveriesEgress,
                         "deliveriesEgress is wrong")
        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='router.address/M0org.apache.dev').deliveriesIngress,
                         "deliveriesIngress is wrong")

        # There should be 4 links -
        # 1. outbound receiver link on org.apache.dev
        # 2. inbound sender link on blocking_sender
        # 3. inbound link to the $management
        # 4. outbound link to $management
        # self.assertEqual(4, len()
        self.assertEquals(4, len(local_node.query(type='org.apache.qpid.dispatch.router.link').results))

        #blocking_receiver.close()
        blocking_connection.close()
开发者ID:ErnieAllen,项目名称:qpid-dispatch,代码行数:54,代码来源:system_tests_link_routes.py

示例9: test_forwarding_sync

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_forwarding_sync(self):
        """
        Forward unsettled messages to multiple subscribers
        """
        config = [
            ('router',   {'mode': 'standalone', 'id': 'QDR.mcast'}),
            ('listener', {'role': 'normal', 'host': '0.0.0.0',
                          'port': self.tester.get_port(),
                          'saslMechanisms':'ANONYMOUS'}),
            ('address', {'pattern': 'nextHop2/#', 'distribution': 'multicast'}),
            ('exchange', {'address':          'Address3',
                          'name':             'Exchange1',
                          'alternateAddress': 'altNextHop'}),
            ('binding', {'name':           'binding1',
                         'exchangeName':   'Exchange1',
                         'bindingKey':     'a.b',
                         'nextHopAddress': 'nextHop1'}),
            ('binding', {'name':           'binding2',
                         'exchangeName':   'Exchange1',
                         'bindingKey':     '*.b',
                         'nextHopAddress': 'nextHop2'})
        ]
        router = self.tester.qdrouterd('QDR.mcast', Qdrouterd.Config(config))

        # create clients for message transfer
        conn = BlockingConnection(router.addresses[0])
        sender = conn.create_sender(address="Address3", options=AtLeastOnce())
        nhop1 = AsyncTestReceiver(address=router.addresses[0], source="nextHop1")
        nhop2A = AsyncTestReceiver(address=router.addresses[0], source="nextHop2")
        nhop2B = AsyncTestReceiver(address=router.addresses[0], source="nextHop2")
        alt = AsyncTestReceiver(address=router.addresses[0], source="altNextHop")

        sender.send(Message(subject='a.b', body='A'))
        sender.send(Message(subject='x.y', body='B'))

        self.assertEqual('A', nhop1.queue.get(timeout=TIMEOUT).body)
        self.assertEqual('A', nhop2A.queue.get(timeout=TIMEOUT).body)
        self.assertEqual('A', nhop2B.queue.get(timeout=TIMEOUT).body)
        self.assertEqual('B', alt.queue.get(timeout=TIMEOUT).body)
        nhop1.stop()
        nhop2A.stop()
        nhop2B.stop()
        alt.stop()
        conn.close()

        self.assertTrue(nhop1.queue.empty())
        self.assertTrue(nhop2A.queue.empty())
        self.assertTrue(nhop2B.queue.empty())
        self.assertTrue(alt.queue.empty())
开发者ID:apache,项目名称:qpid-dispatch,代码行数:51,代码来源:system_tests_exchange_bindings.py

示例10: test_large_messages

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_large_messages(self):
        """
        Verify that multi-frame messages are forwarded properly
        """
        MAX_FRAME=1024
        config = [
            ('router', {'mode': 'interior', 'id': 'QDR.X',
                        'allowUnsettledMulticast': 'yes'}),
            ('listener', {'port': self.tester.get_port(),
                          'stripAnnotations': 'no',
                          'maxFrameSize': MAX_FRAME}),

            ('address', {'pattern': 'nextHop1/#',
                         'distribution': 'multicast'}),

            ('exchange', {'address': 'AddressA',
                          'name': 'ExchangeA'}),

            ('binding', {'name':           'bindingA1',
                         'exchangeName':   'ExchangeA',
                         'bindingKey':     'a/b',
                         'nextHopAddress': 'nextHop1'})
        ]

        router = self.tester.qdrouterd('QDR.X',
                                       Qdrouterd.Config(config),
                                       wait=True)

        # connect clients to router B (no exchange)
        nhop1A = AsyncTestReceiver(router.addresses[0], 'nextHop1',
                                   conn_args={'max_frame_size': MAX_FRAME})
        nhop1B = AsyncTestReceiver(router.addresses[0], 'nextHop1',
                                   conn_args={'max_frame_size': MAX_FRAME})

        conn = BlockingConnection(router.addresses[0],
                                  max_frame_size=MAX_FRAME)
        sender = conn.create_sender(address="AddressA")
        jumbo = (10 * MAX_FRAME) * 'X'
        sender.send(Message(subject='a/b', body=jumbo))

        # multicast
        self.assertEqual(jumbo, nhop1A.queue.get(timeout=TIMEOUT).body)
        self.assertEqual(jumbo, nhop1B.queue.get(timeout=TIMEOUT).body)

        nhop1A.stop()
        nhop1B.stop()
        conn.close()
开发者ID:apache,项目名称:qpid-dispatch,代码行数:49,代码来源:system_tests_exchange_bindings.py

示例11: test_forwarding_fanout

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_forwarding_fanout(self):
        """
        Verify bindings that do not have a key receive all messages
        """
        config = [
            ('exchange', {'address': 'AddressF',
                          'name': 'ExchangeF'}),
            ('binding', {'name':           'binding1',
                         'exchangeName':   'ExchangeF',
                         'bindingKey':     'pattern',
                         'nextHopAddress': 'nextHop1'}),
            # two bindings w/o key
            ('binding', {'name':           'binding2',
                         'exchangeName':   'ExchangeF',
                         'nextHopAddress': 'nextHop2'}),
            ('binding', {'name':           'binding3',
                         'exchangeName':   'ExchangeF',
                         'nextHopAddress': 'nextHop3'})
        ]

        for meth in ['amqp', 'mqtt']:
            config[0][1]['matchMethod'] = meth
            router = self._create_router('A', config)

            # create clients for message transfer
            conn = BlockingConnection(router.addresses[0])
            sender = conn.create_sender(address="AddressF", options=AtMostOnce())
            nhop1 = conn.create_receiver(address="nextHop1", credit=100)
            nhop2 = conn.create_receiver(address="nextHop2", credit=100)
            nhop3 = conn.create_receiver(address="nextHop3", credit=100)

            # send message with subject "nope"
            # should arrive at nextHop2 & 3 only
            sender.send(Message(subject='nope', body='A'))
            self.assertEqual('A', nhop2.receive(timeout=TIMEOUT).body)
            self.assertEqual('A', nhop3.receive(timeout=TIMEOUT).body)

            # send message with subject "pattern"
            # forwarded to all bindings:
            sender.send(Message(subject='pattern', body='B'))
            self.assertEqual('B', nhop1.receive(timeout=TIMEOUT).body)
            self.assertEqual('B', nhop2.receive(timeout=TIMEOUT).body)
            self.assertEqual('B', nhop3.receive(timeout=TIMEOUT).body)

            conn.close()
            router.teardown()
开发者ID:apache,项目名称:qpid-dispatch,代码行数:48,代码来源:system_tests_exchange_bindings.py

示例12: test_full_link_route_match

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_full_link_route_match(self):
        """
        The linkRoutePattern on Routers C and B is set to org.apache.
        Creates a receiver listening on the address 'org.apache' and a sender that sends to address 'org.apache'.
        Sends a message to org.apache via router QDR.C and makes sure that the message was successfully
        routed (using full address matching) and received using pre-created links that were created as a
        result of specifying addresses in the linkRoutePattern attribute('org.apache.').
        """
        hello_world_3 = "Hello World_3!"
        # Connects to listener #2 on QDR.C
        addr = self.routers[2].addresses[1]

        blocking_connection = BlockingConnection(addr)

        # Receive on org.apache
        blocking_receiver = blocking_connection.create_receiver(address="org.apache")

        apply_options = AtMostOnce()

        # Sender to  to org.apache
        blocking_sender = blocking_connection.create_sender(address="org.apache", options=apply_options)
        msg = Message(body=hello_world_3)
        # Send a message
        blocking_sender.send(msg)

        received_message = blocking_receiver.receive()

        self.assertEqual(hello_world_3, received_message.body)

        local_node = Node.connect(self.routers[0].addresses[0], timeout=TIMEOUT)

        # Make sure that the router node acting as the broker (QDR.A) had one message routed through it. This confirms
        # that the message was link routed
        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='router.address/M0org.apache').deliveriesEgress,
                         "deliveriesEgress is wrong")

        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='router.address/M0org.apache').deliveriesIngress,
                         "deliveriesIngress is wrong")

        #blocking_receiver.close()
        blocking_connection.close()
开发者ID:ErnieAllen,项目名称:qpid-dispatch,代码行数:45,代码来源:system_tests_link_routes.py

示例13: test_full_link_route_match_1

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def test_full_link_route_match_1(self):
        """
        This test is pretty much the same as the previous test (test_full_link_route_match) but the connection is
        made to router QDR.B instead of QDR.C and we expect the message to be link routed successfully.
        """
        hello_world_4 = "Hello World_4!"
        addr = self.routers[2].addresses[0]

        blocking_connection = BlockingConnection(addr)

        # Receive on org.apache
        blocking_receiver = blocking_connection.create_receiver(address="org.apache")

        apply_options = AtMostOnce()

        # Sender to  to org.apache
        blocking_sender = blocking_connection.create_sender(address="org.apache", options=apply_options)

        msg = Message(body=hello_world_4)
        # Send a message
        blocking_sender.send(msg)

        received_message = blocking_receiver.receive()

        self.assertEqual(hello_world_4, received_message.body)

        local_node = Node.connect(self.routers[0].addresses[0], timeout=TIMEOUT)

        # Make sure that the router node acting as the broker (QDR.A) had one message routed through it. This confirms
        # that the message was link routed
        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='M0org.apache').deliveriesEgress,
                         "deliveriesEgress is wrong")

        self.assertEqual(1, local_node.read(type='org.apache.qpid.dispatch.router.address',
                                            name='M0org.apache').deliveriesIngress,
                         "deliveriesIngress is wrong")

        blocking_connection.close()
开发者ID:ajssmith,项目名称:qpid-dispatch,代码行数:41,代码来源:system_tests_link_routes.py

示例14: run

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
    def run(self):
        try:
            ssl = SSLDomain(SSLDomain.MODE_CLIENT)
            ssl.set_credentials(str(self.options.accountPublicKey), str(self.options.accountPrivateKey), str(""))
            ssl.set_trusted_ca_db(str(self.options.brokerPublicKey))
            ssl.set_peer_authentication(SSLDomain.VERIFY_PEER_NAME, trusted_CAs=str(self.options.brokerPublicKey))

            connection = BlockingConnection(self.address, ssl_domain=ssl, heartbeat=60000)
            receiver = connection.create_receiver(self.response_address)
            sender = connection.create_sender(self.request_address)

            message = Message(body="<FIXML>...</FIXML>", reply_to=self.reply_adress)
            print("-I- Sending request message: " + message.body)
            sender.send(message);

            try:
                received_message = receiver.receive(timeout=self.options.timeout)
                print("-I- Received response message: " + received_message.body)
                self.message_counter += 1
                receiver.accept()
            except Timeout, e:
                print("-I- No message received for ", self.options.timeout, " seconds")

            connection.close()
开发者ID:Eurex-Clearing-Messaging-Interfaces,项目名称:Python-Code-Examples,代码行数:26,代码来源:BlockingRequestResponse.py

示例15: Connection

# 需要导入模块: from proton.utils import BlockingConnection [as 别名]
# 或者: from proton.utils.BlockingConnection import create_sender [as 别名]
class Connection(BaseConnection):
    """
    Proton connection.
    """

    __metaclass__ = ThreadSingleton

    @staticmethod
    def ssl_domain(connector):
        """
        Get the ssl domain using the broker settings.
        :param connector: A broker.
        :type connector: Connector
        :return: The populated domain.
        :rtype: SSLDomain
        :raise: SSLException
        :raise: ValueError
        """
        domain = None
        if connector.use_ssl():
            connector.ssl.validate()
            domain = SSLDomain(SSLDomain.MODE_CLIENT)
            domain.set_trusted_ca_db(connector.ssl.ca_certificate)
            domain.set_credentials(
                connector.ssl.client_certificate,
                connector.ssl.client_key or connector.ssl.client_certificate, None)
            if connector.ssl.host_validation:
                mode = SSLDomain.VERIFY_PEER_NAME
            else:
                mode = SSLDomain.VERIFY_PEER
            domain.set_peer_authentication(mode)
        return domain

    def __init__(self, url):
        """
        :param url: The connector url.
        :type url: str
        """
        super(Connection, self).__init__(url)
        self._impl = None

    def is_open(self):
        """
        Get whether the connection has been opened.
        :return: True if open.
        :rtype bool
        """
        return self._impl is not None

    @retry(ConnectionException, SSLException)
    def open(self):
        """
        Open a connection to the broker.
        """
        if self.is_open():
            # already open
            return
        connector = Connector.find(self.url)
        domain = self.ssl_domain(connector)
        log.info('open: %s', connector)
        self._impl = BlockingConnection(
            connector.url.canonical,
            heartbeat=connector.heartbeat,
            ssl_domain=domain)
        log.info('opened: %s', self.url)

    def sender(self, address):
        """
        Get a message sender for the specified address.
        :param address: An AMQP address.
        :type address: str
        :return: A sender.
        :rtype: proton.utils.BlockingSender
        """
        name = utf8(uuid4())
        return self._impl.create_sender(address, name=name)

    def receiver(self, address=None, dynamic=False):
        """
        Get a message receiver for the specified address.
        :param address: An AMQP address.
        :type address: str
        :param dynamic: Indicates link address is dynamically assigned.
        :type dynamic: bool
        :return: A receiver.
        :rtype: proton.utils.BlockingReceiver
        """
        options = None
        name = utf8(uuid4())
        if dynamic:
            # needed by dispatch router
            options = DynamicNodeProperties({'x-opt-qd.address': unicode(address)})
            address = None
        return self._impl.create_receiver(address, name=name, dynamic=dynamic, options=options)

    def close(self):
        """
        Close the connection.
        """
        connection = self._impl
#.........这里部分代码省略.........
开发者ID:darinlively,项目名称:gofer,代码行数:103,代码来源:connection.py


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