Iot hub event python
up vote
1
down vote
favorite
I have searched for this quite alot , I am trying to connect a reciever to my iot hub on azure using python , using azure event sdk , but regretably with no success , my reciever tells me it gets connected with the client , but it never actually views the data
my reciever is
#!/usr/bin/env python
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""
An example to show receiving events from an Event Hub partition.
"""
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
# Address can be in either of these formats:
# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS-key>@<mynamespace>.servicebus.windows.net/myeventhub"
# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"
ADDRESS ="amqps://iothub-ns-virtualab2-926709-043cc22e89.servicebus.windows.net/virtualab2"
# SAS policy and key are not required if they are encoded in the URL
USER = "iothubowner"
KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_GROUP = "teststream"
OFFSET = Offset("-1")
PARTITION = "1"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=True, username=USER, password=KEY)
try:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=5000, offset=OFFSET)
client.run()
print("client connected")
start_time = time.time()
print("listening")
batch = receiver.receive(timeout=5000)
while batch:
for event_data in batch:
last_offset = event_data.offset
last_sn = event_data.sequence_number
print("Received: {}, {}".format(last_offset.value, last_sn))
print(event_data.body_as_str())
total += 1
batch = receiver.receive(timeout=5000)
end_time = time.time()
client.stop()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
except KeyboardInterrupt:
pass
finally:
client.stop()
and i am using the standard sender from quickstart from iot hub
python azure iot azure-iot-hub azure-eventhub
add a comment |
up vote
1
down vote
favorite
I have searched for this quite alot , I am trying to connect a reciever to my iot hub on azure using python , using azure event sdk , but regretably with no success , my reciever tells me it gets connected with the client , but it never actually views the data
my reciever is
#!/usr/bin/env python
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""
An example to show receiving events from an Event Hub partition.
"""
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
# Address can be in either of these formats:
# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS-key>@<mynamespace>.servicebus.windows.net/myeventhub"
# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"
ADDRESS ="amqps://iothub-ns-virtualab2-926709-043cc22e89.servicebus.windows.net/virtualab2"
# SAS policy and key are not required if they are encoded in the URL
USER = "iothubowner"
KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_GROUP = "teststream"
OFFSET = Offset("-1")
PARTITION = "1"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=True, username=USER, password=KEY)
try:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=5000, offset=OFFSET)
client.run()
print("client connected")
start_time = time.time()
print("listening")
batch = receiver.receive(timeout=5000)
while batch:
for event_data in batch:
last_offset = event_data.offset
last_sn = event_data.sequence_number
print("Received: {}, {}".format(last_offset.value, last_sn))
print(event_data.body_as_str())
total += 1
batch = receiver.receive(timeout=5000)
end_time = time.time()
client.stop()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
except KeyboardInterrupt:
pass
finally:
client.stop()
and i am using the standard sender from quickstart from iot hub
python azure iot azure-iot-hub azure-eventhub
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have searched for this quite alot , I am trying to connect a reciever to my iot hub on azure using python , using azure event sdk , but regretably with no success , my reciever tells me it gets connected with the client , but it never actually views the data
my reciever is
#!/usr/bin/env python
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""
An example to show receiving events from an Event Hub partition.
"""
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
# Address can be in either of these formats:
# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS-key>@<mynamespace>.servicebus.windows.net/myeventhub"
# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"
ADDRESS ="amqps://iothub-ns-virtualab2-926709-043cc22e89.servicebus.windows.net/virtualab2"
# SAS policy and key are not required if they are encoded in the URL
USER = "iothubowner"
KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_GROUP = "teststream"
OFFSET = Offset("-1")
PARTITION = "1"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=True, username=USER, password=KEY)
try:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=5000, offset=OFFSET)
client.run()
print("client connected")
start_time = time.time()
print("listening")
batch = receiver.receive(timeout=5000)
while batch:
for event_data in batch:
last_offset = event_data.offset
last_sn = event_data.sequence_number
print("Received: {}, {}".format(last_offset.value, last_sn))
print(event_data.body_as_str())
total += 1
batch = receiver.receive(timeout=5000)
end_time = time.time()
client.stop()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
except KeyboardInterrupt:
pass
finally:
client.stop()
and i am using the standard sender from quickstart from iot hub
python azure iot azure-iot-hub azure-eventhub
I have searched for this quite alot , I am trying to connect a reciever to my iot hub on azure using python , using azure event sdk , but regretably with no success , my reciever tells me it gets connected with the client , but it never actually views the data
my reciever is
#!/usr/bin/env python
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""
An example to show receiving events from an Event Hub partition.
"""
import os
import sys
import logging
import time
from azure.eventhub import EventHubClient, Receiver, Offset
# Address can be in either of these formats:
# "amqps://<URL-encoded-SAS-policy>:<URL-encoded-SAS-key>@<mynamespace>.servicebus.windows.net/myeventhub"
# "amqps://<mynamespace>.servicebus.windows.net/myeventhub"
ADDRESS ="amqps://iothub-ns-virtualab2-926709-043cc22e89.servicebus.windows.net/virtualab2"
# SAS policy and key are not required if they are encoded in the URL
USER = "iothubowner"
KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
CONSUMER_GROUP = "teststream"
OFFSET = Offset("-1")
PARTITION = "1"
total = 0
last_sn = -1
last_offset = "-1"
client = EventHubClient(ADDRESS, debug=True, username=USER, password=KEY)
try:
receiver = client.add_receiver(CONSUMER_GROUP, PARTITION, prefetch=5000, offset=OFFSET)
client.run()
print("client connected")
start_time = time.time()
print("listening")
batch = receiver.receive(timeout=5000)
while batch:
for event_data in batch:
last_offset = event_data.offset
last_sn = event_data.sequence_number
print("Received: {}, {}".format(last_offset.value, last_sn))
print(event_data.body_as_str())
total += 1
batch = receiver.receive(timeout=5000)
end_time = time.time()
client.stop()
run_time = end_time - start_time
print("Received {} messages in {} seconds".format(total, run_time))
except KeyboardInterrupt:
pass
finally:
client.stop()
and i am using the standard sender from quickstart from iot hub
python azure iot azure-iot-hub azure-eventhub
python azure iot azure-iot-hub azure-eventhub
asked Nov 10 at 18:56
amr zaki
1113
1113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The code you have does work, however there are a couple of things for you to check:
If you are using the IoT Hub built-in events endpoint, be sure you are using the namespace name from the Event Hub-compatible endpoint and the Event Hub-compatible name for the name. The address I tested with looks like:
amqps://ihsuprodbyresXXXXXXnamespace.servicebus.windows.net/iothub-ehub-sample-XXXXX-XXXXXXXXXX
Be sure you are using the
iothubowner
key value.Be sure the consumer group you're using has been added to the Event Hub-compatible endpoint.
By default, an Event Hub-compatible endpoint has two partitions - your code is only listening for messages on one of them.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The code you have does work, however there are a couple of things for you to check:
If you are using the IoT Hub built-in events endpoint, be sure you are using the namespace name from the Event Hub-compatible endpoint and the Event Hub-compatible name for the name. The address I tested with looks like:
amqps://ihsuprodbyresXXXXXXnamespace.servicebus.windows.net/iothub-ehub-sample-XXXXX-XXXXXXXXXX
Be sure you are using the
iothubowner
key value.Be sure the consumer group you're using has been added to the Event Hub-compatible endpoint.
By default, an Event Hub-compatible endpoint has two partitions - your code is only listening for messages on one of them.
add a comment |
up vote
0
down vote
The code you have does work, however there are a couple of things for you to check:
If you are using the IoT Hub built-in events endpoint, be sure you are using the namespace name from the Event Hub-compatible endpoint and the Event Hub-compatible name for the name. The address I tested with looks like:
amqps://ihsuprodbyresXXXXXXnamespace.servicebus.windows.net/iothub-ehub-sample-XXXXX-XXXXXXXXXX
Be sure you are using the
iothubowner
key value.Be sure the consumer group you're using has been added to the Event Hub-compatible endpoint.
By default, an Event Hub-compatible endpoint has two partitions - your code is only listening for messages on one of them.
add a comment |
up vote
0
down vote
up vote
0
down vote
The code you have does work, however there are a couple of things for you to check:
If you are using the IoT Hub built-in events endpoint, be sure you are using the namespace name from the Event Hub-compatible endpoint and the Event Hub-compatible name for the name. The address I tested with looks like:
amqps://ihsuprodbyresXXXXXXnamespace.servicebus.windows.net/iothub-ehub-sample-XXXXX-XXXXXXXXXX
Be sure you are using the
iothubowner
key value.Be sure the consumer group you're using has been added to the Event Hub-compatible endpoint.
By default, an Event Hub-compatible endpoint has two partitions - your code is only listening for messages on one of them.
The code you have does work, however there are a couple of things for you to check:
If you are using the IoT Hub built-in events endpoint, be sure you are using the namespace name from the Event Hub-compatible endpoint and the Event Hub-compatible name for the name. The address I tested with looks like:
amqps://ihsuprodbyresXXXXXXnamespace.servicebus.windows.net/iothub-ehub-sample-XXXXX-XXXXXXXXXX
Be sure you are using the
iothubowner
key value.Be sure the consumer group you're using has been added to the Event Hub-compatible endpoint.
By default, an Event Hub-compatible endpoint has two partitions - your code is only listening for messages on one of them.
answered Nov 12 at 10:02
Dominic Betts
1,6301410
1,6301410
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242358%2fiot-hub-event-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown