Skip to content

Commit 625882e

Browse files
committed
upgrading to awscrt v0.3.0 WIP
1 parent 496cec8 commit 625882e

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

samples/pubsub.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,32 @@
4545
received_all_event = threading.Event()
4646

4747
# Callback when connection is accidentally lost.
48-
def on_connection_interrupted(error_code):
48+
def on_connection_interrupted(connection, error_code):
4949
print("Connection interrupted. error_code:{}".format(error_code))
5050

5151
# Callback when an interrupted connection is re-established.
52-
def on_connection_resumed(error_code, session_present):
52+
def on_connection_resumed(connection, error_code, session_present):
5353
print("Connection resumed. error_code:{} session_present:{}".format(error_code, session_present))
5454

55+
if not session_present:
56+
print("Server did not save state. Resubscribing to existing topics...")
57+
resubscribe_future, _ = connection.resubscribe_existing_topics()
58+
59+
# Cannot synchronously wait for resubscribe result because we're on the connection's event-loop thread,
60+
# evaluate result with a callback instead.
61+
def on_resubscribed(resubscribe_future):
62+
try:
63+
resubscribe_results = resubscribe_future.result()
64+
print("Resubscribe complete. results:{}".format(resubscribe_results))
65+
for topic, qos in resubscribe_results['topics']:
66+
assert(qos)
67+
except Exception as e:
68+
print("Resubscribe failed. Exiting", e)
69+
exit(-1)
70+
71+
resubscribe_future.add_done_callback(on_resubscribed)
72+
73+
5574
# Callback when the subscribed topic receives a message
5675
def on_message_received(topic, message):
5776
print("Received message from topic '{}': {}".format(topic, message))
@@ -67,7 +86,7 @@ def on_message_received(topic, message):
6786

6887
tls_options = io.TlsContextOptions.create_client_with_mtls_from_path(args.cert, args.key)
6988
if args.root_ca:
70-
tls_options.override_default_trust_store_from_path(ca_path=None, ca_file=args.root_ca)
89+
tls_options.override_default_trust_store_from_path(ca_dirpath=None, ca_filepath=args.root_ca)
7190
tls_context = io.ClientTlsContext(tls_options)
7291

7392
mqtt_client = mqtt.Client(client_bootstrap, tls_context)
@@ -89,7 +108,7 @@ def on_message_received(topic, message):
89108
port = port,
90109
use_websocket=False,
91110
clean_session=True,
92-
keep_alive=6000)
111+
keep_alive=5) # DO NOT COMMIT THIS CHANGE
93112

94113
# Future.result() waits until a result is available
95114
connect_future.result()

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
description='AWS IoT SDK based on the AWS Common Runtime',
2222
author='AWS SDK Common Runtime Team',
2323
url='https://github.com/awslabs/aws-iot-device-sdk-python-v2',
24-
packages = find_packages(),
24+
packages = ['awsiot'],
2525
install_requires=[
26-
'awscrt==0.2.16',
27-
'futures; python_version == "2.7"',
28-
'typing; python_version <= "3.4"',
26+
'awscrt==0.3.0',
27+
'futures;python_version<"3.2"',
28+
'typing;python_version<"3.5"',
2929
],
3030
python_requires='>=2.7',
3131
)

0 commit comments

Comments
 (0)