From ba6b085dce1b485fa9dd68ac0151b5f2b4970a64 Mon Sep 17 00:00:00 2001 From: Sudhir Date: Tue, 14 Jul 2015 15:50:44 +0530 Subject: [PATCH] PythonToEventHub --- PythonToEventHub | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 PythonToEventHub diff --git a/PythonToEventHub b/PythonToEventHub new file mode 100644 index 0000000..4faecac --- /dev/null +++ b/PythonToEventHub @@ -0,0 +1,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