[
https://issues.apache.org/jira/browse/PROTON-2044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16839751#comment-16839751
]
Andrew Stitcher commented on PROTON-2044:
-----------------------------------------
the reason you are getting disconnected is that you aren't runnign any code
that is sending heartbeat frames to hold open the connection.
If you use the BlockingConnection to send/receive messages then Proton is only
able to send protocol frames over the connected socket when you are in the
BlockingConnection code. So if you send or receive a message and then go and do
something else for longer than the heartbeat time your peer should disconnect
you for being idle as you didn't keep the connection awake.
The solution is either to sit in BlockingConnection waiting for a
message/acknowledgement most of the time - in which cased you may need to do
other work in another thread of your code. Or just to accept that disconnects
are inevitable and reconnect when you want to send a message if you've been
disconnected.
In any case Servicebus will disconnect you after some time if you do nothing
even if you do send heartbeats, but this is on the order of minutes I think.
But this means that you really need to be able to reconnect for any kind of
reliable operation.
> 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
> Fix For: proton-c-0.24.0
>
>
> 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]