Iot hub event python











up vote
1
down vote

favorite
1












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










share|improve this question


























    up vote
    1
    down vote

    favorite
    1












    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










    share|improve this question
























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      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










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 18:56









      amr zaki

      1113




      1113
























          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.









          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            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

























            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.









            share|improve this answer

























              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.









              share|improve this answer























                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.









                share|improve this answer












                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.










                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 10:02









                Dominic Betts

                1,6301410




                1,6301410






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Bressuire

                    Vorschmack

                    Quarantine