Commit a0a03a38 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

add brokerrest to thing

parent 5d3f934f
......@@ -150,7 +150,7 @@ def build(thing_ref, attributes):
build_sub_featrues(thing_ref, feature_proxy, json_feature)
def create_dt_ref(model, grant_type, secret, username, password, is_broker, is_repo):
def create_dt_ref(model, grant_type, secret, username, password, is_broker_rest, is_broker, is_repo):
"""Creates a ditigal twin, runs it in an own thread and returns a
reference to it.
......@@ -185,6 +185,7 @@ def create_dt_ref(model, grant_type, secret, username, password, is_broker, is_r
client_secret=secret,
username=username,
password=password,
is_broker_rest=is_broker_rest,
is_broker=is_broker,
is_repo=is_repo
)
......
......@@ -3,13 +3,13 @@
import websocket
import json
import uuid
from s3i import IdentityProvider, TokenType, Broker, GetValueReply, Directory
from s3i.broker import BrokerREST
import requests
from s3i import IdentityProvider, TokenType, GetValueReply, Directory
from s3i.broker import Broker, BrokerREST, BrokerMetaClass
from s3i.messages import ServiceReply
from ml.managing_actor import ManagingActor
from ml.tools import BColors
from ml.tools import send_message
from ml.tools import find_broker_endpoint
from ml.app_logger import APP_LOGGER
......@@ -214,6 +214,8 @@ def receive():
target=receive,
).start()
else:
self.broker = Broker(
auth_form="Username/Password",
......@@ -279,7 +281,7 @@ def on_get_value_request(self, msg):
replyingToUUID=request_msg_id,
)
msg_txt = get_value_reply.msg.__str__()
self.broker.send(
send_resp = self.broker.send(
receiver_endpoints=[request_sender_endpoint], msg=msg_txt,
)
......@@ -290,7 +292,7 @@ def on_service_request(self, body_json):
if service_functionality_obj is None:
APP_LOGGER.critical(
"Functionality %s is not one of the built-in functionalities in %s!" % (
service_functionality, self.name)
service_functionality, self.name)
)
else:
pass
......@@ -306,9 +308,14 @@ def on_service_request(self, body_json):
serviceType=body_json.get("serviceType", None),
results=result,
replyingToUUID=body_json.get("identifier", None),
msgUUID=str(uuid.uuid4())
msgUUID="s3i:{}".format(uuid.uuid4())
)
send_message(self.broker, self.dir, service_reply.msg)
receiver_eps = list()
for r in service_reply.msg.get("receivers", None):
receiver_ep = find_broker_endpoint(self.dir, r)
receiver_eps.append(receiver_ep)
self.broker.send(receiver_endpoints=receiver_eps, msg=json.dumps(service_reply.msg))
def on_get_value_reply(self, msg):
print(msg)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment