-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscriber.py
39 lines (28 loc) · 1.23 KB
/
subscriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import asyncio
import logging
from message import TopicMessageReceiverStrategy
from client import ServiceBusClientFactory
from utils import (ServiceBusSubscriber,
configure_logging,
namespace_name,
string_message_handler,
subscription_name,
topic_name)
# Connection String Based Publisher If It Set to True Otherwise Use Default Azure Login
USE_CONNECTION_STR = True
NAMESPACE = namespace_name()
TOPIC = topic_name()
SUBSCRIPTION_NAME = subscription_name()
SUBSCRIBER = ServiceBusSubscriber(namespace=NAMESPACE,
queue_or_topic_name=TOPIC,
strategy=TopicMessageReceiverStrategy,
use_connection_str=USE_CONNECTION_STR)
async def main():
await SUBSCRIBER.start_listening(message_handler=string_message_handler,
subscription_name=SUBSCRIPTION_NAME)
if isinstance(SUBSCRIBER.factory_object, ServiceBusClientFactory):
await SUBSCRIBER.factory_object._credential.close()
if __name__ == "__main__":
configure_logging()
logging.getLogger('azure').setLevel(logging.WARNING)
asyncio.run(main())