コード例 #1
0
    def on_start(self, event):
        conn = event.container.connect(self.address)
        # The receiver sets link.snd_settle_mode = Link.SND_SETTLED. It wants to receive settled messages
        self.receiver = event.container.create_receiver(conn, "org/apache/dev", options=AtMostOnce())

        # With AtLeastOnce, the sender will not settle.
        self.sender = event.container.create_sender(conn, "org/apache/dev", options=AtLeastOnce())
コード例 #2
0
 def on_link_remote_open(self, event):
     link = event.link
     if link.is_receiver:
         self.sender = self.ssn.sender("Perfy-TX")
         self.sender.target.address = self.target
         AtLeastOnce().apply(self.sender)
         self.sender.open()
コード例 #3
0
    def test_17_address_wildcard(self):
        # verify proper distribution is selected by wildcard
        addresses = [
            # (address, count of messages expected to be received)
            ('a.b.c.d',   1), # closest 'a.b.c.d'
            ('b.c.d',     2), # multi   '#.b.c.d'
            ('f.a.b.c.d', 2), # multi   '#.b.c.d
            ('a.c.d',     2), # multi   'a.*.d'
            ('a/c/c/d',   1), # closest 'a/*/#.d
            ('a/x/z/z/d', 1), # closest 'a/*/#.d
            ('a/x/d',     1), # closest 'a.x.d'
            ('a.x.e',     1), # balanced  ----
            ('m.b.c.d',   2)  # multi   '*/b/c/d'
        ]

        # two receivers per address - one for each router
        receivers = []
        for a in addresses:
            for x in range(2):
                ar = AsyncTestReceiver(address=self.routers[x].addresses[0],
                                       source=a[0])
                receivers.append(ar)

        # wait for the consumer info to propagate
        for a in addresses:
            self.routers[0].wait_address(a[0], 1, 1)
            self.routers[1].wait_address(a[0], 1, 1)

        # send one message to each address
        conn = BlockingConnection(self.routers[0].addresses[0])
        sender = conn.create_sender(address=None, options=AtLeastOnce())
        for a in addresses:
            sender.send(Message(address=a[0], body={'address': a[0]}))

        # count received messages by address
        msgs_recvd = {}
        for M in receivers:
            try:
                while True:
                    i = M.queue.get(timeout=0.2).body.get('address', "ERROR")
                    if i not in msgs_recvd:
                        msgs_recvd[i] = 0
                    msgs_recvd[i] += 1
            except AsyncTestReceiver.Empty:
                pass

        # verify expected count == actual count
        self.assertTrue("ERROR" not in msgs_recvd)
        for a in addresses:
            self.assertTrue(a[0] in msgs_recvd)
            self.assertEqual(a[1], msgs_recvd[a[0]])

        for M in receivers:
            M.stop()
        conn.close()
コード例 #4
0
    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())
コード例 #5
0
    def test_remote_exchange(self):
        """
        Verify that the exchange and bindings are visible to other routers in
        the network
        """

        def router(self, name, extra_config):

            config = [
                ('router', {'mode': 'interior', 'id': 'QDR.%s' % name, 'allowUnsettledMulticast': 'yes'}),
                ('listener', {'port': self.tester.get_port(), 'stripAnnotations': 'no'})
            ] + extra_config

            config = Qdrouterd.Config(config)

            self.routers.append(self.tester.qdrouterd(name, config, wait=True))

        self.inter_router_port = self.tester.get_port()
        self.routers = []

        router(self, 'A',
               [('listener',
                 {'role': 'inter-router', 'port': self.inter_router_port}),

                ('address', {'pattern': 'nextHop1/#',
                             'distribution': 'multicast'}),
                ('address', {'pattern': 'nextHop2/#',
                             'distribution': 'balanced'}),
                ('address', {'pattern': 'nextHop3/#',
                             'distribution': 'closest'}),

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

                ('binding', {'name':           'bindingA1',
                             'exchangeName':   'ExchangeA',
                             'bindingKey':     'a/b',
                             'nextHopAddress': 'nextHop1'}),
                ('binding', {'name':           'bindingA2',
                             'exchangeName':   'ExchangeA',
                             'bindingKey':     'a/+',
                             'nextHopAddress': 'nextHop2'}),
                ('binding', {'name':           'bindingA3',
                             'exchangeName':   'ExchangeA',
                             'bindingKey':     '+/b',
                             'nextHopAddress': 'nextHop3'}),
                ('binding', {'name':           'bindingA4',
                             'exchangeName':   'ExchangeA',
                             'bindingKey':     'a/#',
                             'nextHopAddress': 'NotSubscribed'})
                ])

        router(self, 'B',
               [('connector', {'name': 'connectorToA',
                               'role': 'inter-router',
                               'port': self.inter_router_port}),
                ('address', {'pattern': 'nextHop1/#',
                             'distribution': 'multicast'}),
                ('address', {'pattern': 'nextHop2/#',
                             'distribution': 'balanced'}),
                ('address', {'pattern': 'nextHop3/#',
                             'distribution': 'closest'})
                ])

        self.routers[0].wait_router_connected('QDR.B')
        self.routers[1].wait_router_connected('QDR.A')
        self.routers[1].wait_address('AddressA')

        # connect clients to router B (no exchange)
        nhop1A = AsyncTestReceiver(self.routers[1].addresses[0], 'nextHop1')
        nhop1B = AsyncTestReceiver(self.routers[1].addresses[0], 'nextHop1')
        nhop2  = AsyncTestReceiver(self.routers[1].addresses[0], 'nextHop2')
        nhop3  = AsyncTestReceiver(self.routers[1].addresses[0], 'nextHop3')

        self.routers[0].wait_address('nextHop1', remotes=1)
        self.routers[0].wait_address('nextHop2', remotes=1)
        self.routers[0].wait_address('nextHop3', remotes=1)

        conn = BlockingConnection(self.routers[1].addresses[0])
        sender = conn.create_sender(address="AddressA", options=AtLeastOnce())
        sender.send(Message(subject='a/b', body='Hi!'))

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

        # balanced and closest
        self.assertEqual('Hi!', nhop2.queue.get(timeout=TIMEOUT).body)
        self.assertEqual('Hi!', nhop3.queue.get(timeout=TIMEOUT).body)

        nhop1A.stop()
        nhop1B.stop()
        nhop2.stop()
        nhop3.stop()
        conn.close()
コード例 #6
0
 def on_connection_opened(self, event):
     self._sender = self._container.create_sender(self._conn,
                                                  target=self.target,
                                                  options=AtLeastOnce())
コード例 #7
0
 def on_start(self, event):
     event.container.create_sender(self.url, options=AtLeastOnce())