Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
KWH40
fml40-reference-implementation
Commits
d435b0b0
Commit
d435b0b0
authored
Apr 01, 2021
by
Jiahang Chen
Browse files
fix broker rest interface
parent
6f930d36
Pipeline
#439294
passed with stages
in 51 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ml/thing.py
View file @
d435b0b0
...
...
@@ -394,20 +394,21 @@ def __connect_with_broker(self):
)
if
self
.
__is_broker_rest
:
self
.
broker
=
BrokerREST
(
token
=
self
.
access_token
)
def
receive
():
self
.
__endpoint
=
find_broker_endpoint
(
self
.
dir
,
thing_id
=
self
.
thing_id
)
while
True
:
try
:
time
.
sleep
(
0.1
)
msg_str
=
self
.
broker
.
receive_once
(
self
.
__endpoint
)
if
msg_str
==
""
:
msg
=
self
.
broker
.
receive_once
(
self
.
__endpoint
)
msg_to_json
=
lambda
msg
:
msg
if
isinstance
(
msg
,
dict
)
else
json
.
loads
(
msg
)
if
msg
==
{}:
continue
else
:
self
.
__on_broker_callback
(
ch
=
None
,
method
=
None
,
properties
=
None
,
body
=
json
.
loads
(
msg_str
),
body
=
msg_to_json
(
msg
),
)
except
:
continue
...
...
@@ -453,7 +454,8 @@ def __on_broker_callback(self, ch, method, properties, body):
elif
isinstance
(
body
,
str
):
pass
self
.
broker
.
receiver
.
acknowledge_message
(
method
.
delivery_tag
)
if
ch
is
not
None
:
ch
.
basic_ack
(
method
.
delivery_tag
)
try
:
message_type
=
body
.
get
(
"messageType"
)
if
message_type
==
"userMessage"
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment