-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-queue-reader.py
More file actions
30 lines (24 loc) · 861 Bytes
/
example-queue-reader.py
File metadata and controls
30 lines (24 loc) · 861 Bytes
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
# example-queue-reader
# Simple script to test receiving events through the queue
#
# Copyright 2019 Peter Upfold
#
# Licensed under the Apache 2.0 Licence.
from azure.servicebus import ServiceBusClient
import yaml
config_file = open('config.yml', 'r')
config = yaml.safe_load(config_file)
bus_service = ServiceBusClient(
service_namespace=config['namespace'],
shared_access_key_name=config['shared_access_key_name'],
shared_access_key_value=config['shared_access_key_value'])
queue_client = bus_service.get_queue(config['queue_name'])
messages = queue_client.get_receiver()
for message in messages:
if len(str(message)) > 0:
print(message)
with open(config['output_file'], 'w') as output_file:
output_file.write(str(message))
else:
print('Zero-length message')
message.complete()