关于python中Service Bus订阅的相关性过滤器的文档不多。所有示例都涉及SQL过滤器。我试图应用与那里看到的相同的逻辑,但无济于事。
我有一个简单的测试用例,其中我要创建两个订阅,每个订阅都有一个关联过滤器。一个过滤器根据相关性id =高过滤,另一个过滤器对低过滤。
new = []
for L in range(0, len(stuff)+1):
for subset in itertools.combinations(stuff, L):
if sum(subset) == 10170090:
new.append(subset)
new = list(map(list, new))
for i in new:
lst = iter(list(zip(stuff, words)))
a = next(lst)
for idx, item in enumerate(i):
while True:
if item == a[0] and a[1] == 'RFQ_DELETED':
i[idx] = a[1]
break
elif item == a[0]:
i[idx] = a[1]
a = next(lst)
break
else:
a = next(lst)
print(new)
[['AGGGG', 'AUDIT + PARK', 'AUDIT + PENDING', 'PENDING'],
['AGGGG', 'AUDIT + PENDING', 'LIVE', 'PENDING'],
['AGGGG', 'AUDIT + PENDING', 'PENDING', 'RFQ_DELETED'],
['AGGGG', 'AUDIT + PARK', 'AUDIT + PENDING', 'AUDIT + QUOTE_CREATED,AUDIT + QUOTE_DELETED', 'REJECT'],
['AGGGG', 'AUDIT + PENDING', 'AUDIT + QUOTE_CREATED,AUDIT + QUOTE_DELETED', 'LIVE', 'REJECT'],
...
['AGGGG', 'AUDIT + PENDING', 'AUDIT + QUOTE_CREATED,AUDIT + QUOTE_DELETED', 'AUDIT + QUOTE_REJECTED', 'LIVE', 'QUOTE_CREATED', 'RFQ_DELETED'],
['AGGGG', 'AUDIT + PENDING', 'AUDIT + QUOTE_REJECTED', 'AUDIT + QUOTE_UPDATED', 'LIVE', 'REJECT', 'RFQ_DELETED'],
['AGGGG', 'AUDIT + PENDING', 'AUDIT + QUOTE_REJECTED', 'LIVE', 'QUOTE_CREATED', 'REJECT', 'RFQ_DELETED'],
['AGGGG', 'AUDIT + PENDING', 'AUDIT + QUOTE_REJECTED', 'LIVE', 'QUOTE_CREATED', 'REJECT', 'RFQ_DELETED']
]
我正在通过发送correlation_id设置为低的消息来测试这些过滤器。
_create_subscription(bus_service, 'filter-test-topic', 'highsub')
high_rule = Rule()
high_rule.filter_type = 'CorrelationFilter'
high_rule.correlation_filter = CorrelationFilter(correlation_id='high')
bus_service.create_rule('filter-test-topic', 'highsub', 'HighMessageFilter', high_rule)
bus_service.delete_rule('filter-test-topic', 'highsub', DEFAULT_RULE_NAME)
_create_subscription(bus_service, 'filter-test-topic', 'lowsub')
low_rule = Rule()
low_rule.filter_type = 'CorrelationFilter'
low_rule.filter_expression = CorrelationFilter(correlation_id='low')
bus_service.create_rule('filter-test-topic', 'lowsub', 'LowMessageFilter', low_rule)
bus_service.delete_rule('filter-test-topic', 'lowsub', DEFAULT_RULE_NAME)
我希望在“ lowsub”中看到5条消息,在“ highsub”中看到0条消息。但是,当我检查azure门户时,两个订阅都有0条消息。
我可以正确创建过滤器吗?我是否在消息中正确设置了correlation_id?我不确定我在做什么错。