-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonToEventHub
25 lines (19 loc) · 893 Bytes
/
PythonToEventHub
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
#import random because using one of the functions in code
import random
from azure.servicebus import ServiceBusService
# SharedAccessKeyName from Azure Portal
key_name ='RootManageSharedAccessKey'
# SharedAccessKey from Azure Portal
key_value=''
# Pointing to Microsoft Azure Service Bus
sbs = ServiceBusService('SERVICE_BUS_NAME', shared_access_key_name=key_name, shared_access_key_value=key_value)
# Event Hub Creation
sbs.create_event_hub('hubcreationfromlinux')
# Some randomg values
devicecounts = 5
eventcounts = 1000
for eventcount in range (1, eventcounts) :
deviceId = "dev-" + str(random.randrange (1, devicecounts))
temperature = str(float("{0:.2f}".format(random.uniform (0,50))))
sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + temperature +'"}')
print "DeviceId : " + deviceId + " Temperature : " + temperature