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()
def on_start(self, event): event.container.create_sender(self.url, options=AtMostOnce())
# Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # import os from system_test import TestCase, Qdrouterd, main_module, TIMEOUT, DIR, Process from system_test import QdManager from proton.utils import BlockingConnection from proton import Message from proton.reactor import AtMostOnce apply_options = AtMostOnce() class LogLevelUpdateTest(TestCase): @classmethod def setUpClass(cls): super(LogLevelUpdateTest, cls).setUpClass() name = "test-router" LogLevelUpdateTest.listen_port = cls.tester.get_port() config = Qdrouterd.Config([('router', { 'mode': 'standalone', 'id': 'QDR' }), ('listener', { 'port': LogLevelUpdateTest.listen_port }), ('address', { 'prefix': 'closest',
def test_forwarding_mqtt(self): """ Simple forwarding over a single mqtt exchange """ config = [ ('exchange', {'address': 'Address2', 'name': 'Exchange1', 'matchMethod': 'mqtt', 'alternateAddress': 'altNextHop'}), ('binding', {'name': 'binding1', 'exchangeName': 'Exchange1', 'bindingKey': 'a/b', 'nextHopAddress': 'nextHop1'}), ('binding', {'name': 'binding2', 'exchangeName': 'Exchange1', 'bindingKey': 'a/+', 'nextHopAddress': 'nextHop2'}), ('binding', {'name': 'binding3', 'exchangeName': 'Exchange1', 'bindingKey': 'c/#', 'nextHopAddress': 'nextHop1'}), ('binding', {'name': 'binding4', 'exchangeName': 'Exchange1', 'bindingKey': 'c/b', 'nextHopAddress': 'nextHop2'}), ] router = self._create_router('B', config) # create clients for message transfer conn = BlockingConnection(router.addresses[0]) sender = conn.create_sender(address="Address2", options=AtMostOnce()) nhop1 = conn.create_receiver(address="nextHop1", credit=100) nhop2 = conn.create_receiver(address="nextHop2", credit=100) alt = conn.create_receiver(address="altNextHop", credit=100) # send message with subject "a.b" # matches (binding1, binding2) # forwarded to NextHop1, NextHop2 sender.send(Message(subject='a/b', body='A')) self.assertEqual('A', nhop1.receive(timeout=TIMEOUT).body) self.assertEqual('A', nhop2.receive(timeout=TIMEOUT).body) # send message with subject "a/c" # matches binding2 # -> NextHop2 sender.send(Message(subject='a/c', body='B')) self.assertEqual('B', nhop2.receive(timeout=TIMEOUT).body) # send message with subject "c/b" # matches bindings 3,4 # -> NextHop1, NextHop2 sender.send(Message(subject='c/b', body='C')) self.assertEqual('C', nhop1.receive(timeout=TIMEOUT).body) self.assertEqual('C', nhop2.receive(timeout=TIMEOUT).body) # send message with subject "c/b/dee/eee" # matches binding3 # -> NextHop1 sender.send(Message(subject='c/b/dee/eee', body='D')) self.assertEqual('D', nhop1.receive(timeout=TIMEOUT).body) # send message with subject "x.y.z" # no binding match # -> alternate sender.send(Message(subject='x.y.z', body="?")) self.assertEqual('?', alt.receive(timeout=TIMEOUT).body) # ensure there are no more messages on either hop: self.assertRaises(Timeout, nhop1.receive, timeout=0.25) self.assertRaises(Timeout, nhop2.receive, timeout=0.25) self.assertRaises(Timeout, alt.receive, timeout=0.25) # validate counters self._validate_binding(router, name='binding1', matchedCount=1) self._validate_binding(router, name='binding2', matchedCount=2) self._validate_binding(router, name='binding3', matchedCount=2) self._validate_binding(router, name='binding4', matchedCount=1) self._validate_exchange(router, name="Exchange1", receivedCount=5, forwardedCount=5, divertedCount=1, droppedCount=0) conn.close()
def test_forwarding(self): """ Simple forwarding over a single 0-10 exchange """ config = [ ('exchange', {'address': 'Address1', 'name': 'Exchange1', 'matchMethod': 'amqp'}), # two different patterns, same next hop: ('binding', {'name': 'binding1', 'exchangeName': 'Exchange1', 'bindingKey': 'a.*', 'nextHopAddress': 'nextHop1'}), ('binding', {'name': 'binding2', 'exchangeName': 'Exchange1', 'bindingKey': 'a.b', 'nextHopAddress': 'nextHop1'}), # duplicate patterns, different next hops: ('binding', {'name': 'binding3', 'exchangeName': 'Exchange1', 'bindingKey': 'a.c.#', 'nextHopAddress': 'nextHop1'}), ('binding', {'name': 'binding4', 'exchangeName': 'Exchange1', 'bindingKey': 'a.c.#', 'nextHopAddress': 'nextHop2'}), # match for nextHop2 only ('binding', {'name': 'binding5', 'exchangeName': 'Exchange1', 'bindingKey': 'a.b.c', 'nextHopAddress': 'nextHop2'}) ] router = self._create_router('A', config) # create clients for message transfer conn = BlockingConnection(router.addresses[0]) sender = conn.create_sender(address="Address1", options=AtMostOnce()) nhop1 = conn.create_receiver(address="nextHop1", credit=100) nhop2 = conn.create_receiver(address="nextHop2", credit=100) # verify initial metrics self._validate_exchange(router, name='Exchange1', bindingCount=5, receivedCount=0, droppedCount=0, forwardedCount=0, divertedCount=0) for b in range(5): self._validate_binding(router, name='binding%s' % (b + 1), matchedCount=0) # send message with subject "a.b" # matches (binding1, binding2) # forwarded to NextHop1 only sender.send(Message(subject='a.b', body='A')) self.assertEqual('A', nhop1.receive(timeout=TIMEOUT).body) # send message with subject "a.c" # matches (bindings 1,3,4) # -> NextHop1, NextHop2 sender.send(Message(subject='a.c', body='B')) self.assertEqual('B', nhop1.receive(timeout=TIMEOUT).body) self.assertEqual('B', nhop2.receive(timeout=TIMEOUT).body) # send message with subject "a.c.d" # matches bindings 3,4 # -> NextHop1, NextHop2 sender.send(Message(subject='a.c.d', body='C')) self.assertEqual('C', nhop1.receive(timeout=TIMEOUT).body) self.assertEqual('C', nhop2.receive(timeout=TIMEOUT).body) # send message with subject "x.y.z" # no binding match - expected to drop # not forwarded sender.send(Message(subject='x.y.z', body=["I am Noone"])) # send message with subject "a.b.c" # matches binding5 # -> NextHop2 sender.send(Message(subject='a.b.c', body='D')) self.assertEqual('D', nhop2.receive(timeout=TIMEOUT).body) # ensure there are no more messages on either hop: self.assertRaises(Timeout, nhop1.receive, timeout=0.25) self.assertRaises(Timeout, nhop2.receive, timeout=0.25) # validate counters self._validate_binding(router, name='binding1', matchedCount=2) self._validate_binding(router, name='binding2', matchedCount=1) self._validate_binding(router, name='binding3', matchedCount=2) self._validate_binding(router, name='binding4', matchedCount=2) self._validate_binding(router, name='binding5', matchedCount=1) self._validate_exchange(router, name="Exchange1", receivedCount=5, forwardedCount=4, divertedCount=0, droppedCount=1) conn.close()
def test_zzz_qdmanage_delete_link_route(self): """ We are deleting the link route using qdmanage short name. This should be the last test to run """ # First delete linkRoutes on QDR.B local_node = Node.connect(self.routers[1].addresses[0], timeout=TIMEOUT) result_list = local_node.query( type='org.apache.qpid.dispatch.router.config.linkRoute').results identity_1 = result_list[0][1] identity_2 = result_list[1][1] identity_3 = result_list[2][1] identity_4 = result_list[3][1] cmd = 'DELETE --type=linkRoute --identity=' + identity_1 self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) cmd = 'DELETE --type=linkRoute --identity=' + identity_2 self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) cmd = 'DELETE --type=linkRoute --identity=' + identity_3 self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) cmd = 'DELETE --type=linkRoute --identity=' + identity_4 self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) cmd = 'QUERY --type=linkRoute' out = self.run_qdmanage(cmd=cmd, address=self.routers[1].addresses[0]) self.assertEquals(out.rstrip(), '[]') # linkRoutes now gone on QDR.B but remember that it still exist on QDR.C # We will now try to create a receiver on address org.apache.dev on QDR.C. # Since the linkRoute on QDR.B is gone, QDR.C # will not allow a receiver to be created since there is no route to destination. # Connects to listener #2 on QDR.C addr = self.routers[2].addresses[0] # Now delete linkRoutes on QDR.C to eradicate linkRoutes completely local_node = Node.connect(addr, timeout=TIMEOUT) result_list = local_node.query( type='org.apache.qpid.dispatch.router.config.linkRoute').results identity_1 = result_list[0][1] identity_2 = result_list[1][1] identity_3 = result_list[2][1] identity_4 = result_list[3][1] identity_4 = result_list[3][1] cmd = 'DELETE --type=linkRoute --identity=' + identity_1 self.run_qdmanage(cmd=cmd, address=addr) cmd = 'DELETE --type=linkRoute --identity=' + identity_2 self.run_qdmanage(cmd=cmd, address=addr) cmd = 'DELETE --type=linkRoute --identity=' + identity_3 self.run_qdmanage(cmd=cmd, address=addr) cmd = 'DELETE --type=linkRoute --identity=' + identity_4 self.run_qdmanage(cmd=cmd, address=addr) cmd = 'QUERY --type=linkRoute' out = self.run_qdmanage(cmd=cmd, address=addr) self.assertEquals(out.rstrip(), '[]') blocking_connection = BlockingConnection(addr, timeout=3) # Receive on org.apache.dev (this address used to be linkRouted but not anymore since we deleted linkRoutes # on both QDR.C and QDR.B) blocking_receiver = blocking_connection.create_receiver( address="org.apache.dev") apply_options = AtMostOnce() hello_world_1 = "Hello World_1!" # Sender 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(timeout=5) self.assertEqual(hello_world_1, received_message.body)
def test_ddd_partial_link_route_match(self): """ The linkRoute 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 linkRoute attribute('org.apache.'). """ hello_world_1 = "Hello World_1!" # Connects to listener #2 on QDR.C addr = self.routers[2].addresses[0] blocking_connection = BlockingConnection(addr) # Receive on org.apache.dev blocking_receiver = blocking_connection.create_receiver( address="org.apache.dev") apply_options = AtMostOnce() # Sender 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=['id']).results[0][0]) self.assertEqual( 1, local_node.read(type='org.apache.qpid.dispatch.router.address', name='M0org.apache.dev').deliveriesEgress) self.assertEqual( 1, local_node.read(type='org.apache.qpid.dispatch.router.address', name='M0org.apache.dev').deliveriesIngress) # 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_connection.close()
def on_start(self, event): print('on_start') event.container.selectable(self.events) event.container.create_receiver(self.receiver_address) event.container.create_sender(self.sender_address, options=AtMostOnce())
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())
def on_connection_remote_open(self, event): if event.connection == self.receiver_connection: continue_loop = True # Dont open the sender connection unless we can make sure that there is a remote receiver ready to # accept the message. # If there is no remote receiver, the router will throw a 'No route to destination' error when # creating sender connection. # The following loops introduces a wait before creating the sender connection. It gives time to the # router so that the address Dpulp.task can show up on the remoteCount i = 0 while continue_loop: if i > 100: # If we have run the read command for more than hundred times and we still do not have # the remoteCount set to 1, there is a problem, just exit out of the function instead # of looping to infinity. self.receiver_connection.close() return local_node = Node.connect(self.qdstat_address, timeout=TIMEOUT) out = local_node.read(type='org.apache.qpid.dispatch.router.address', name='Dpulp.task').remoteCount if out == 1: continue_loop = False else: i += 1 sleep(0.25) self.sender_connection = event.container.connect(self.sender_address) self.sender = event.container.create_sender(self.sender_connection, "pulp.task", options=AtMostOnce())