[ 
https://issues.apache.org/jira/browse/PROTON-2044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16855636#comment-16855636
 ] 

Andreas Fendt commented on PROTON-2044:
---------------------------------------

{quote}It seems that you're trying to use the BlockingConnection when you 
really want to just use a regular event style application - see the python 
example code for how to use the event handling code.{quote}

It may really be better to use something other than the BlockingConnection. 
Unfortunately I can't deduce from the examples below how I could solve the 
problem.

{quote}Another possibility is just to recognise the disconnect exception and 
reconnect and send the message - as I said if you are connected to servicebus 
for long enough without sending a message you will get disconnected anyway - so 
you have to handle a case very like it anyway.{quote}

It's true that it's important to find out if the connection needs to be aborted 
and restarted. But as already described there are two timeouts at Servicebus: 
the short timeout which is caused by missing heartbeats. This already happens 
after 15 seconds. The other timeout happens only about 10 minutes. To 
reestablish the connection every 15 seconds just doesn't make sense in my eyes.

> Azure IoT Hub local-idle-timeout expired
> ----------------------------------------
>
>                 Key: PROTON-2044
>                 URL: https://issues.apache.org/jira/browse/PROTON-2044
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: python-binding
>    Affects Versions: proton-c-0.24.0
>         Environment: Operating System: Windows
> Python: 3.6.4
> qpid-proton: 0.24.0
>            Reporter: Andreas Fendt
>            Priority: Major
>
> I'm using following python code to send messages to the devices 
> (*/messages/devicebound*) which are connected to the *azure iot hub*:
> {code}
> import json
> from base64 import b64encode, b64decode
> from hashlib import sha256
> from hmac import HMAC
> from time import time
> from urllib.parse import quote_plus, urlencode
> from proton import ProtonException, Message
> from proton.utils import BlockingConnection
> class IotHub:
>     def __init__(self):
>         self._hostname = f"example-hub.azure-devices.net"
>         self._username = f"[email protected]"
>         self._blocking_connection = None
>         self._sender = None
>         self.connect()
>     @staticmethod
>     def generate_sas_token(uri: str, policy: str, key: str, expiry: float = 
> None):
>         if not expiry:
>             expiry = time() + 3600  # Default to 1 hour.
>         encoded_uri = quote_plus(uri)
>         ttl = int(expiry)
>         sign_key = f"{encoded_uri}\n{ttl}"
>         signature = b64encode(HMAC(b64decode(key), sign_key.encode(), 
> sha256).digest())
>         result = {"sr": uri, "sig": signature, "se": str(ttl)}
>         if policy:
>             result["skn"] = policy
>         return f"SharedAccessSignature {urlencode(result)}"
>     def connect(self):
>         # create credentials
>         password = self.generate_sas_token(self._hostname,
>                                            "iothubowner", "key",
>                                            time() + 31557600)  # ttl = 1 Year
>         # establish connection
>         self._blocking_connection = 
> BlockingConnection(f"amqps://{self._hostname}", allowed_mechs="PLAIN",
>                                                        user=self._username, 
> password=password,
>                                                        heartbeat=30)
>         self._sender = 
> self._blocking_connection.create_sender("/messages/devicebound")
>     def send(self, message: dict, serial_number: str):
>         message = 
> Message(address="/devices/{serial_number}/messages/devicebound".format(serial_number=serial_number),
>                           body=bytes(json.dumps(message, separators=(",", 
> ":")), "utf-8"))
>         message.inferred = True  # disable message encoding
>         self._sender.send(message, timeout=20)
> {code}
> The problem is now that when I don't send any message for some seconds I get 
> following exepction while sending a message:
> {code:java}
> Connection amqps://example-hub.azure-devices.net:amqps disconnected: 
> Condition('amqp:resource-limit-exceeded', 'local-idle-timeout expired')
> {code}
> Whats the reason for that? How can I solve that?
> Thank you for help.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to