You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Andreas Fendt (JIRA)" <ji...@apache.org> on 2019/05/08 16:35:00 UTC
[jira] [Updated] (PROTON-2044) Azure IoT Hub local-idle-timeout
expired
[ https://issues.apache.org/jira/browse/PROTON-2044?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andreas Fendt updated PROTON-2044:
----------------------------------
Description:
I'm using following python code to send messages to the devices which are connected to the azure iot hub:
{code:python}
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"iothubowner@sas.root.example-hub.azure-devices.net"
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?
was:
I'm using following python code to send messages to the devices which are connected to the azure iot hub:
{code:java}
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"iothubowner@sas.root.example-hub.azure-devices.net"
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):
"""
Send proton Message to AMQP queue
"""
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?
> 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 which are connected to the azure iot hub:
> {code:python}
> 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"iothubowner@sas.root.example-hub.azure-devices.net"
> 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?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org