本文整理汇总了Python中amqpstorm.Channel.build_inbound_messages方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.build_inbound_messages方法的具体用法?Python Channel.build_inbound_messages怎么用?Python Channel.build_inbound_messages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amqpstorm.Channel
的用法示例。
在下文中一共展示了Channel.build_inbound_messages方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_build_empty_inbound_messages
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_build_empty_inbound_messages(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
result = None
for message in channel.build_inbound_messages(break_on_empty=True):
result = message
self.assertIsNone(result)
示例2: test_channel_build_inbound_raises
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_inbound_raises(self, _):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
generator = channel.build_inbound_messages(break_on_empty=False)
if hasattr(generator, 'next'):
self.assertRaises(AMQPChannelError, generator.next)
else:
self.assertRaises(AMQPChannelError, generator.__next__)
示例3: test_channel_build_empty_inbound_messages
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_empty_inbound_messages(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
generator = channel.build_inbound_messages(break_on_empty=True)
if hasattr(generator, 'next'):
self.assertRaises(StopIteration, generator.next)
else:
self.assertRaises(StopIteration, generator.__next__)
示例4: test_build_inbound_messages
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_build_inbound_messages(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
message = b'Hello World!'
message_len = len(message)
deliver = specification.Basic.Deliver()
header = ContentHeader(body_size=message_len)
body = ContentBody(value=message)
channel._inbound = [deliver, header, body]
for message in channel.build_inbound_messages(break_on_empty=True):
self.assertIsInstance(message, Message)
示例5: test_channel_build_inbound_raises_in_loop
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_inbound_raises_in_loop(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
self.first = True
def raise_after_one(**_):
if not self.first:
channel.exceptions.append(AMQPChannelError())
self.first = False
return None
with mock.patch('amqpstorm.Channel._build_message',
side_effect=raise_after_one):
generator = channel.build_inbound_messages(break_on_empty=False)
if hasattr(generator, 'next'):
self.assertRaises(AMQPChannelError, generator.next)
else:
self.assertRaises(AMQPChannelError, generator.__next__)
示例6: test_channel_build_inbound_messages
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_inbound_messages(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
message = self.message.encode('utf-8')
message_len = len(message)
deliver = specification.Basic.Deliver()
header = ContentHeader(body_size=message_len)
body = ContentBody(value=message)
channel._inbound = [deliver, header, body]
messages_consumed = 0
for msg in channel.build_inbound_messages(break_on_empty=True):
self.assertIsInstance(msg, Message)
messages_consumed += 1
self.assertEqual(messages_consumed, 1)
示例7: test_channel_build_no_message_but_inbound_not_empty
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_no_message_but_inbound_not_empty(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(Channel.OPEN)
message = self.message.encode('utf-8')
message_len = len(message)
def add_content():
channel._inbound.append(ContentHeader(body_size=message_len))
channel._inbound.append(ContentBody(value=message))
deliver = specification.Basic.Deliver()
channel._inbound = [deliver]
self.assertTrue(channel._inbound)
threading.Timer(function=add_content, interval=0.2).start()
for msg in channel.build_inbound_messages(break_on_empty=True):
self.assertEqual(msg.body, message.decode('utf-8'))
self.assertFalse(channel._inbound)
示例8: test_channel_build_inbound_messages_without_break_on_empty
# 需要导入模块: from amqpstorm import Channel [as 别名]
# 或者: from amqpstorm.Channel import build_inbound_messages [as 别名]
def test_channel_build_inbound_messages_without_break_on_empty(self):
channel = Channel(0, FakeConnection(), 360)
channel.set_state(channel.OPEN)
message = self.message.encode('utf-8')
message_len = len(message)
deliver = specification.Basic.Deliver()
header = ContentHeader(body_size=message_len)
body = ContentBody(value=message)
for _ in range(25):
channel._inbound.append(deliver)
channel._inbound.append(header)
channel._inbound.append(body)
messages_consumed = 0
for msg in channel.build_inbound_messages(break_on_empty=False):
messages_consumed += 1
self.assertIsInstance(msg.body, str)
self.assertEqual(msg.body.encode('utf-8'), message)
if messages_consumed >= 10:
channel.set_state(channel.CLOSED)
self.assertEqual(messages_consumed, 10)