當前位置: 首頁>>代碼示例>>Python>>正文


Python basic_message.Message類代碼示例

本文整理匯總了Python中amqp.basic_message.Message的典型用法代碼示例。如果您正苦於以下問題:Python Message類的具體用法?Python Message怎麽用?Python Message使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Message類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_inbound_header__empty_body

 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack(">HxxQ", m.CLASS_ID, 0)
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=0), 12)
     self.assertTrue(m.ready)
開發者ID:c0b,項目名稱:py-amqp,代碼行數:7,代碼來源:test_serialization.py

示例2: enqueue

 def enqueue(self, tag, data, schedule = None, error_times=0, channel=None):
     with self.open(channel):
         self.setup_tag(tag)
         msg = Message()
         msg.properties['delivery_mode'] = 2
         body = {'i': self.gensym(), 'c': data, 'e': error_times}
         id = None
         if schedule:
             ttl = round_by_accuracy(get_millis_to_the_date(schedule), self.SCHEDULING_ACCURACY)
             ttl1 = min(ttl, self.TTL_MAX)
             stag = ('%s.%s' % (self.get_tag(tag, 'SCHEDULE'), str(ttl1), ))
             self.channel.queue_declare(
                 queue=stag, durable=True, auto_delete=False,
                 arguments = { 'x-message-ttl' : ttl1, "x-dead-letter-exchange" : self.get_tag(tag, 'EXCHANGE') }
             )
             body['s'] = schedule.strftime(self.TIME_FORMAT)
             msg.body = self.serializer(body)
             id = self.channel.basic_publish(msg, routing_key=stag)
             log(" [%s] Sent scheduled -> ttl: %s(%s) schedule: %s" % (body['i'], ttl1, ttl, body['s'], ))
         else:
             rtag = self.get_tag(tag, 'READY')
             msg.body = self.serializer(body)
             id = self.channel.basic_publish(msg, routing_key=rtag)
             log(" [%s] Sent immediate -> tag: %s" % (body['i'], rtag))
         return body['i']
開發者ID:smihica,項目名稱:py-q4rmq,代碼行數:25,代碼來源:q4rmq.py

示例3: test_inbound_header__empty_body

 def test_inbound_header__empty_body(self):
     m = Message()
     m.properties = {}
     buf = pack(b'>HxxQ', m.CLASS_ID, 0)
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=0) == 12
     assert m.ready
開發者ID:air-upc,項目名稱:py-amqp,代碼行數:7,代碼來源:test_serialization.py

示例4: test_inbound_header

 def test_inbound_header(self):
     m = Message()
     m.properties = {"content_type": "application/json", "content_encoding": "utf-8"}
     body = "the quick brown fox"
     buf = b"\0" * 30 + pack(">HxxQ", m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=30), 42)
     self.assertEqual(m.body_size, len(body))
     self.assertEqual(m.properties["content_type"], "application/json")
     self.assertFalse(m.ready)
開發者ID:c0b,項目名稱:py-amqp,代碼行數:10,代碼來源:test_serialization.py

示例5: test_message

 def test_message(self):
     m = Message(
         'foo',
         channel=Mock(name='channel'),
         application_headers={'h': 'v'},
     )
     m.delivery_info = {'delivery_tag': '1234'},
     assert m.body == 'foo'
     assert m.channel
     assert m.headers == {'h': 'v'}
開發者ID:Itxaka,項目名稱:py-amqp,代碼行數:10,代碼來源:test_basic_message.py

示例6: test_message

 def test_message(self):
     m = Message(
         'foo',
         channel=Mock(name='channel'),
         application_headers={'h': 'v'},
     )
     m.delivery_info = {'delivery_tag': '1234'},
     self.assertEqual(m.body, 'foo')
     self.assertTrue(m.channel)
     self.assertDictEqual(m.headers, {'h': 'v'})
開發者ID:adamchainz,項目名稱:py-amqp,代碼行數:10,代碼來源:test_basic_message.py

示例7: check_proplist

    def check_proplist(self, msg):
        """
        Check roundtrip processing of a single object

        """
        raw_properties = msg._serialize_properties()

        new_msg = Message()
        new_msg._load_properties(raw_properties)
        new_msg.body = msg.body

        self.assertEqual(msg, new_msg)
開發者ID:SYNchroACK,項目名稱:crits_dependencies,代碼行數:12,代碼來源:test_basic_message.py

示例8: test_inbound_header

 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack(b'>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     assert m.inbound_header(buf, offset=30) == 42
     assert m.body_size == len(body)
     assert m.properties['content_type'] == 'application/json'
     assert not m.ready
開發者ID:air-upc,項目名稱:py-amqp,代碼行數:13,代碼來源:test_serialization.py

示例9: test_inbound_header

 def test_inbound_header(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
     }
     body = 'the quick brown fox'
     buf = b'\0' * 30 + pack(b'>HxxQ', m.CLASS_ID, len(body))
     buf += m._serialize_properties()
     self.assertEqual(m.inbound_header(buf, offset=30), 42)
     self.assertEqual(m.body_size, len(body))
     self.assertEqual(m.properties['content_type'], 'application/json')
     self.assertFalse(m.ready)
開發者ID:odedlaz,項目名稱:py-amqp,代碼行數:13,代碼來源:test_serialization.py

示例10: test_inbound_body

 def test_inbound_body(self):
     m = Message()
     m.body_size = 16
     m.body_received = 8
     m._pending_chunks = [b'the', b'quick']
     m.inbound_body(b'brown')
     self.assertFalse(m.ready)
     m.inbound_body(b'fox')
     self.assertTrue(m.ready)
     self.assertEqual(m.body, b'thequickbrownfox')
開發者ID:odedlaz,項目名稱:py-amqp,代碼行數:10,代碼來源:test_serialization.py

示例11: test_inbound_body

 def test_inbound_body(self):
     m = Message()
     m.body_size = 16
     m.body_received = 8
     m._pending_chunks = [b'the', b'quick']
     m.inbound_body(b'brown')
     assert not m.ready
     m.inbound_body(b'fox')
     assert m.ready
     assert m.body == b'thequickbrownfox'
開發者ID:air-upc,項目名稱:py-amqp,代碼行數:10,代碼來源:test_serialization.py

示例12: test_header_message_empty_body

    def test_header_message_empty_body(self):
        assert not self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))
        self.callback.assert_not_called()

        with pytest.raises(UnexpectedFrame):
            self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))

        m = Message()
        m.properties = {}
        buf = pack('>HxxQ', m.CLASS_ID, 0)
        buf += m._serialize_properties()
        assert self.g((2, 1, buf))

        self.callback.assert_called()
        msg = self.callback.call_args[0][3]
        self.callback.assert_called_with(
            1, msg.frame_method, msg.frame_args, msg,
        )
開發者ID:Itxaka,項目名稱:py-amqp,代碼行數:18,代碼來源:test_method_framing.py

示例13: test_header_message_content

    def test_header_message_content(self):
        assert not self.g((1, 1, pack('>HH', *spec.Basic.Deliver)))
        self.callback.assert_not_called()

        m = Message()
        m.properties = {}
        buf = pack('>HxxQ', m.CLASS_ID, 16)
        buf += m._serialize_properties()
        assert not self.g((2, 1, buf))
        self.callback.assert_not_called()

        assert not self.g((3, 1, b'thequick'))
        self.callback.assert_not_called()

        assert self.g((3, 1, b'brownfox'))
        self.callback.assert_called()
        msg = self.callback.call_args[0][3]
        self.callback.assert_called_with(
            1, msg.frame_method, msg.frame_args, msg,
        )
        assert msg.body == b'thequickbrownfox'
開發者ID:Itxaka,項目名稱:py-amqp,代碼行數:21,代碼來源:test_method_framing.py

示例14: test_load_properties

 def test_load_properties(self):
     m = Message()
     m.properties = {
         'content_type': 'application/json',
         'content_encoding': 'utf-8',
         'application_headers': {
             'foo': 1,
             'id': 'id#1',
         },
         'delivery_mode': 1,
         'priority': 255,
         'correlation_id': 'df31-142f-34fd-g42d',
         'reply_to': 'cosmo',
         'expiration': '2015-12-23',
         'message_id': '3312',
         'timestamp': 3912491234,
         'type': 'generic',
         'user_id': 'george',
         'app_id': 'vandelay',
         'cluster_id': 'NYC',
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
     assert m2.properties == m.properties
開發者ID:air-upc,項目名稱:py-amqp,代碼行數:25,代碼來源:test_serialization.py

示例15: test_load_properties__some_missing

 def test_load_properties__some_missing(self):
     m = Message()
     m.properties = {
         "content_type": "application/json",
         "content_encoding": "utf-8",
         "delivery_mode": 1,
         "correlation_id": "df31-142f-34fd-g42d",
         "reply_to": "cosmo",
         "expiration": "2015-12-23",
         "message_id": "3312",
         "type": None,
         "app_id": None,
         "cluster_id": None,
     }
     s = m._serialize_properties()
     m2 = Message()
     m2._load_properties(m2.CLASS_ID, s)
開發者ID:c0b,項目名稱:py-amqp,代碼行數:17,代碼來源:test_serialization.py


注:本文中的amqp.basic_message.Message類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。