示例#1
0
    def on_sendable(self, event):
        if self.num_messages < 2:
            request = Message()
            request.correlation_id = "C1"
            request.address = "amqp:/_local/$management"
            request.properties = {
                u'type': u'org.amqp.management',
                u'name': u'self',
                u'operation': u'GET-MGMT-NODES'
            }
            request.reply_to = self.receiver.remote_source.address
            event.sender.send(request)
            self.num_messages += 1

            request = Message()
            request.address = "amqp:/_topo/0/QDR.B/$management"
            request.correlation_id = "C2"
            request.reply_to = self.receiver.remote_source.address
            request.properties = {
                u'type': u'org.amqp.management',
                u'name': u'self',
                u'operation': u'GET-MGMT-NODES'
            }
            event.sender.send(request)
            self.num_messages += 1
    def test_09_management(self):
        addr  = "amqp:/$management"

        M = self.messenger()
        M.start()
        M.route("amqp:/*", self.address+"/$1")
        sub = M.subscribe("amqp:/#")
        reply = sub.address

        request  = Message()
        response = Message()

        request.address        = addr
        request.reply_to       = reply
        request.correlation_id = "C1"
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        assert response.properties['statusCode'] == 200, response.properties['statusCode']
        self.assertEqual(response.correlation_id, "C1")
        self.assertEqual(response.body, [])

        request.address        = addr
        request.reply_to       = reply
        request.correlation_id = 135
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        self.assertEqual(response.properties['statusCode'], 200)
        self.assertEqual(response.correlation_id, 135)
        self.assertEqual(response.body, [])

        request.address        = addr
        request.reply_to       = reply
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        self.assertEqual(response.properties['statusCode'], 200)
        self.assertEqual(response.body, [])

        M.stop()
    def test_09_management(self):
        addr  = "amqp:/$management"

        M = self.messenger()
        M.start()
        M.route("amqp:/*", self.address+"/$1")
        sub = M.subscribe("amqp:/#")
        reply = sub.address

        request  = Message()
        response = Message()

        request.address        = addr
        request.reply_to       = reply
        request.correlation_id = "C1"
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        assert response.properties['statusCode'] == 200, response.properties['statusCode']
        self.assertEqual(response.correlation_id, "C1")
        self.assertEqual(response.body, [])

        request.address        = addr
        request.reply_to       = reply
        request.correlation_id = 135
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        self.assertEqual(response.properties['statusCode'], 200)
        self.assertEqual(response.correlation_id, 135)
        self.assertEqual(response.body, [])

        request.address        = addr
        request.reply_to       = reply
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()
        M.recv()
        M.get(response)

        self.assertEqual(response.properties['statusCode'], 200)
        self.assertEqual(response.body, [])

        M.stop()
示例#4
0
def zaqar_to_proton(message):
    """Convert a message retrieved from storage to a Proton message"""
    msg = Message()

    msg.ttl = message.get('ttl')
    msg.body = message.get('body')

    # NOTE(vkmc) This won't work for now - there is no 'amqp10' field yet
    if message.get('amqp10'):
        msg.priority = message.get('amqp10').get('priority')
        msg.first_acquirer = message.get('amqp10').get('first_acquirer')
        msg.delivery_count = message.get('amqp10').get('delivery_count')
        msg.id = message.get('amqp10').get('id'),
        msg.user_id = message.get('amqp10').get('user_id')
        msg.address = message.get('amqp10').get('address')
        msg.subject = message.get('amqp10').get('subject')
        msg.reply_to = message.get('amqp10').get('reply_to')
        msg.correlation_id = message.get('amqp10').get('correlation_id')
        msg.content_type = message.get('amqp10').get('content_type')
        msg.content_encoding = message.get('amqp10').get('content_encoding')
        msg.expiry_time = message.get('amqp10').get('expiry_time')
        msg.creation_time = message.get('amqp10').get('creation_time'),
        msg.group_id = message.get('amqp10').get('group_id')
        msg.group_sequence = message.get('amqp10').get('group_sequence')
        msg.reply_to_group_id = message.get('amqp10').get('reply_to_group_id')
        msg.format = message.get('amqp10').get('format')

    return msg
示例#5
0
    def _send_request(self):
        """Send a message containing the RPC method call
        """
        msg = Message()
        msg.subject = "An RPC call!"
        msg.address = self._to
        msg.reply_to = self._reply_to
        msg.body = self._method
        msg.correlation_id = 5  # whatever...

        print("sending RPC call request: %s" % str(self._method))
        # @todo send timeout self._sender.send(msg, self, None, time.time() +
        # 10)
        self._sender.send(msg, self)
示例#6
0
    def _send_request(self):
        """Send a message containing the RPC method call
        """
        msg = Message()
        msg.subject = "An RPC call!"
        msg.address = self._to
        msg.reply_to = self._reply_to
        msg.body = self._method
        msg.correlation_id = 5  # whatever...

        print("sending RPC call request: %s" % str(self._method))
        # @todo send timeout self._sender.send(msg, self, None, time.time() +
        # 10)
        self._sender.send(msg, self)
示例#7
0
 def run(self):
     while (True):
         if self.mng.incoming < 1:
             self.mng.recv(1)
         if self.mng.incoming > 0:
             request = Message()
             self.mng.get(request)
             if request.reply_to:
                 response = Message()
                 response.address = request.reply_to
                 response.correlation_id = request.correlation_id
                 response.properties = {}
                 response.properties['result'], response.body = self.process(request.properties, request.body)
                 self.mng.put(response)
                 self.mng.send()
示例#8
0
    def message_received(self, receiver_link, message, handle):
        LOG.debug("message received callback")

        global reply_senders

        # extract to reply-to, correlation id
        reply_to = message.reply_to
        if not reply_to or reply_to not in reply_senders:
            LOG.error("sender for reply-to not found, reply-to=%s",
                      str(reply_to))
            info = Condition("not-found",
                             "Bad reply-to address: %s" % str(reply_to))
            self._link.message_rejected(handle, info)
        else:
            my_sender = reply_senders[reply_to]
            correlation_id = message.correlation_id
            method_map = message.body
            if (not isinstance(method_map, dict) or
                    'method' not in method_map):
                LOG.error("no method given, map=%s", str(method_map))
                info = Condition("invalid-field",
                                 "no method given, map=%s" % str(method_map))
                self._link.message_rejected(handle, info)
            else:
                response = Message()
                response.address = reply_to
                response.subject = message.subject
                response.correlation_id = correlation_id
                response.body = {"response": method_map}

                print("RPC request received, msg=%s" % str(method_map))
                print("  to address=%s" % str(message.address))
                print("  replying to=%s" % str(reply_to))
                link = my_sender.sender_link
                # @todo send timeouts
                # link.send( response, my_sender,
                #            message, time.time() + 5.0)
                link.send(response, my_sender, message)

                self._link.message_accepted(handle)

        if self._link.capacity == 0:
            LOG.debug("increasing credit...")
            self._link.add_capacity(5)
示例#9
0
    def message_received(self, receiver_link, message, handle):
        LOG.debug("message received callback")

        global reply_senders

        # extract to reply-to, correlation id
        reply_to = message.reply_to
        if not reply_to or reply_to not in reply_senders:
            LOG.error("sender for reply-to not found, reply-to=%s",
                      str(reply_to))
            info = Condition("not-found",
                             "Bad reply-to address: %s" % str(reply_to))
            self._link.message_rejected(handle, info)
        else:
            my_sender = reply_senders[reply_to]
            correlation_id = message.correlation_id
            method_map = message.body
            if (not isinstance(method_map, dict)
                    or 'method' not in method_map):
                LOG.error("no method given, map=%s", str(method_map))
                info = Condition("invalid-field",
                                 "no method given, map=%s" % str(method_map))
                self._link.message_rejected(handle, info)
            else:
                response = Message()
                response.address = reply_to
                response.subject = message.subject
                response.correlation_id = correlation_id
                response.body = {"response": method_map}

                print("RPC request received, msg=%s" % str(method_map))
                print("  to address=%s" % str(message.address))
                print("  replying to=%s" % str(reply_to))
                link = my_sender.sender_link
                # @todo send timeouts
                # link.send( response, my_sender,
                #            message, time.time() + 5.0)
                link.send(response, my_sender, message)

                self._link.message_accepted(handle)

        if self._link.capacity == 0:
            LOG.debug("increasing credit...")
            self._link.add_capacity(5)
示例#10
0
    def on_message(self, event):
        request = event.message

        print("RESPOND: Received request '{0}'".format(request.body))

        response_body = request.body.upper()

        response = Message(response_body)
        response.address = request.reply_to
        response.correlation_id = request.id

        self.sender.send(response)

        print("RESPOND: Sent response '{0}'".format(response.body))

        self.received += 1

        if self.received == self.desired:
            event.receiver.close()
            event.connection.close()
    def test_09a_management_no_reply(self):
        addr  = "amqp:/$management"

        M = self.messenger()
        M.start()
        M.route("amqp:/*", self.address+"/$1")

        request  = Message()

        request.address        = addr
        request.correlation_id = "C1"
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()

        M.put(request)
        M.send()

        M.stop()
    def test_09a_management_no_reply(self):
        addr  = "amqp:/$management"

        M = self.messenger()
        M.start()
        M.route("amqp:/*", self.address+"/$1")

        request  = Message()

        request.address        = addr
        request.correlation_id = "C1"
        request.properties     = {u'type':u'org.amqp.management', u'name':u'self', u'operation':u'GET-MGMT-NODES'}

        M.put(request)
        M.send()

        M.put(request)
        M.send()

        M.stop()
示例#13
0
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = BINARY('testuser')
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
 def on_sendable(self, event):
     if not self.sent:
         msg = Message()
         msg.address = self.address
         msg.id = '123455'
         msg.user_id = 'testuser'
         msg.subject = 'test-subject'
         msg.content_type = 'text/html; charset=utf-8'
         msg.correlation_id = 89
         msg.creation_time = 1487772623.883
         msg.group_id = "group1"
         msg.reply_to = 'hello_world'
         msg.content_encoding = 'gzip, deflate'
         msg.reply_to_group_id = "group0"
         application_properties = dict()
         application_properties['app-property'] = [10, 20, 30]
         application_properties['some-other'] = symbol("O_one")
         msg.properties = application_properties
         msg.body = u"Hello World!"
         event.sender.send(msg)
         self.sent = True
示例#15
0
    def GetObject(self, cls):
        request = Message()
        response = Message()

        request.address = self.address
        request.reply_to = self.reply
        request.correlation_id = 1
        request.properties = {u'operation':u'GET', u'type':cls}
        request.body = {'attributeNames': []}

        self.M.put(request)
        self.M.send()
        self.M.recv()
        self.M.get(response)

        if response.properties['status-code'] != 200:
            raise Exception("Agent reports: %d %s" % (response.properties['status-code'], response.properties['status-description']))

        entities = []
        results = response.body
        for e in results:
            entities.append(AmqpEntity(e))

        return entities
    def test_03_bad_response_message(self):
        """
        Test various improperly constructed response messages
        """
        DUMMY_TESTS = {
            "GET": [
                (
                    RequestMsg("GET",
                               "/GET/test_03_bad_response_message",
                               headers={"Content-Length": "000"}),
                    None,
                    None,
                ),
            ]
        }

        body_filler = "?" * 1024 * 300  # Q2

        # fake server - just to create a sink for the "fakeServer" address so
        # credit will be granted.
        rx = AsyncTestReceiver(self.INT_A.listener, source="fakeServer")

        # no correlation id:
        client = ThreadedTestClient(DUMMY_TESTS, self.http_fake_port)
        req = rx.queue.get(timeout=TIMEOUT)
        resp = Message(body="NO CORRELATION ID " + body_filler)
        resp.to = req.reply_to
        ts = AsyncTestSender(address=self.INT_A.listener,
                             target=req.reply_to,
                             message=resp)
        ts.wait()
        self.assertEqual(1, ts.rejected)
        client.wait()
        self.assertIsNotNone(client.error)

        # missing application properties
        client = ThreadedTestClient(DUMMY_TESTS, self.http_fake_port)
        req = rx.queue.get(timeout=TIMEOUT)

        resp = Message(body="NO APPLICATION PROPS " + body_filler)
        resp.to = req.reply_to
        resp.correlation_id = req.id
        ts = AsyncTestSender(address=self.INT_A.listener,
                             target=req.reply_to,
                             message=resp)
        ts.wait()
        self.assertEqual(1, ts.rejected)
        client.wait()
        self.assertIsNotNone(client.error)

        # no status application property
        client = ThreadedTestClient(DUMMY_TESTS, self.http_fake_port)
        req = rx.queue.get(timeout=TIMEOUT)
        resp = Message(body="MISSING STATUS HEADER " + body_filler)
        resp.to = req.reply_to
        resp.correlation_id = req.id
        resp.properties = {"stuff": "value"}
        ts = AsyncTestSender(address=self.INT_A.listener,
                             target=req.reply_to,
                             message=resp)
        ts.wait()
        self.assertEqual(1, ts.rejected)
        client.wait()
        self.assertIsNotNone(client.error)

        # TODO: fix body parsing (returns NEED_MORE)
        # # invalid body format
        # client = ThreadedTestClient(DUMMY_TESTS,
        #                             self.http_fake_port)
        # req = rx.queue.get(timeout=TIMEOUT)
        # resp = Message(body="INVALID BODY FORMAT " + body_filler)
        # resp.to = req.reply_to
        # resp.correlation_id = req.id
        # resp.properties = {"http:status": 200}
        # ts = AsyncTestSender(address=self.INT_A.listener,
        #                      target=req.reply_to,
        #                      message=resp)
        # ts.wait()
        # self.assertEqual(1, ts.rejected);
        # client.wait()
        # self.assertIsNotNone(client.error)

        rx.stop()
        sleep(0.5)  # fudge factor allow socket close to complete

        # verify router is still sane:
        count, error = http1_ping(self.http_server_port,
                                  self.http_listener_port)
        self.assertIsNone(error)
        self.assertEqual(1, count)