本文整理汇总了Python中azure.servicebus.ServiceBusService.with_filter方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceBusService.with_filter方法的具体用法?Python ServiceBusService.with_filter怎么用?Python ServiceBusService.with_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.servicebus.ServiceBusService
的用法示例。
在下文中一共展示了ServiceBusService.with_filter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServiceBusTest
# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import with_filter [as 别名]
#.........这里部分代码省略.........
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
sent_msg = Message('subscription message')
self.sbs.send_topic_message(self.topic_name, sent_msg)
# Act
received_msg = self.sbs.receive_subscription_message(
self.topic_name, 'MySubscription', True, 5)
received_msg.delete()
# Assert
self.assertIsNotNone(received_msg)
self.assertEquals(sent_msg.body, received_msg.body)
def test_receive_subscription_message_unlock(self):
# Arrange
self._create_topic_and_subscription(self.topic_name, 'MySubscription')
sent_msg = Message('subscription message')
self.sbs.send_topic_message(self.topic_name, sent_msg)
# Act
received_msg = self.sbs.receive_subscription_message(
self.topic_name, 'MySubscription', True)
received_msg.unlock()
# Assert
received_again_msg = self.sbs.receive_subscription_message(
self.topic_name, 'MySubscription', True)
received_again_msg.delete()
self.assertIsNotNone(received_msg)
self.assertIsNotNone(received_again_msg)
self.assertEquals(sent_msg.body, received_msg.body)
self.assertEquals(received_again_msg.body, received_msg.body)
def test_with_filter(self):
# Single filter
called = []
def my_filter(request, next):
called.append(True)
return next(request)
sbs = self.sbs.with_filter(my_filter)
sbs.create_topic(self.topic_name + '0', None, True)
self.assertTrue(called)
del called[:]
sbs.delete_topic(self.topic_name + '0')
self.assertTrue(called)
del called[:]
# Chained filters
def filter_a(request, next):
called.append('a')
return next(request)
def filter_b(request, next):
called.append('b')
return next(request)
sbs = self.sbs.with_filter(filter_a).with_filter(filter_b)
sbs.create_topic(self.topic_name + '0', None, True)
self.assertEqual(called, ['b', 'a'])