# if required, add a loop (with timeout) to wait for myMsbClient.connected and myMsbClient.registered myMsbClient.connect() myMsbClient.register() def sendData(): while True: # add your test events here #myMsbClient.publish( # eventId="EVENT_ID", # event id # dataObject="Hello World!", # event value (or object) # priority=0, # event priority #) # wait 5 seconds time.sleep(5) if __name__ == "__main__": # initialize msb client (application.properties used for client params) myMsbClient = MsbClient() # setup msb client setupMsbClient() # run msb client in a thread msbClientThread = threading.Thread(target=runMsbClient, args=()) msbClientThread.start() # send events in a thread (every 5 seconds to tests them) sendDataThread = threading.Thread(target=sendData, args=()) sendDataThread.start()
from msb_client.TypeDescriptor import TypeDescriptor from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "Application" SO_UUID = "7fe43e5a-8638-4e0c-bca5-c576375d2bc1" SO_NAME = "Verification Service 4" SO_DESCRIPTION = "Raspberry PI 3 + Enviro+ sensor board" SO_TOKEN = "c576375d2bc1" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) msb_url = "wss://192.168.1.9:8084" myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableHostnameVerification(True)
"""This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "Application" SO_UUID = "4d239249-9473-4bd6-b980-cad1710e2d2e" SO_NAME = "ERP Job Management Service" SO_DESCRIPTION = "ERP Job Management Database Service" SO_TOKEN = "cad1710e2d2e" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableHostnameVerification(True) myMsbClient.enableThreadAsDaemon(False) print(myMsbClient.objectToJson(myMsbClient.getSelfDescription()))
import datetime import threading import uuid import time from msb_client.ComplexDataFormat import ComplexDataFormat from msb_client.DataType import DataType from msb_client.Event import Event from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": myMsbClient = MsbClient() myMsbClient.enableDebug(True) myMsbClient.disableHostnameVerification(True) myMsbClient.disableEventCache(False) print(myMsbClient.objectToJson(myMsbClient.getSelfDescription())) myMsbClient.connect() myMsbClient.register()
from msb_client.TypeDescriptor import TypeDescriptor from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "Application" SO_UUID = "a6f425ac-9e7b-4837-b7e8-5084fda42d30" SO_NAME = "Flow Test Service 1" SO_DESCRIPTION = "Flow Test Service 1" SO_TOKEN = "5084fda42d30" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) # msb_url = "wss://192.168.0.67:8084" msb_url = "wss://192.168.1.9:8084" myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableHostnameVerification(True)
import threading import uuid import time from msb_client.ComplexDataFormat import ComplexDataFormat from msb_client.DataType import DataType from msb_client.Event import Event from msb_client.Function import Function from msb_client.MsbClient import MsbClient def printMsg(msg): print(str(msg["dataObject"])) if __name__ == "__main__": myMsbClient = MsbClient() myMsbClient.enableDebug(True) myMsbClient.disableHostnameVerification(True) myMsbClient.disableEventCache(False) myMsbClient.addEvent( event="event1", # event id event_name="Event Name", event_description="Event Description", event_dataformat=DataType.STRING, ) myMsbClient.addFunction( function="function1", # function id function_name="Function Name",
def setup_msbclient(verification_token): logging.debug("Setup MSB Client") # Init msb client global myMsbClient myMsbClient = MsbClient( "SmartObject", SO_UUID, SO_NAME, SO_DESCRIPTION, verification_token ) myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableHostnameVerification(True) myMsbClient.enableThreadAsDaemon(True) # add a configuration parameter to the self description config_param_name_1 = "testParam1" config_param_value_1 = True config_param_datatype_1 = bool config_param_name_2 = "testParam2" config_param_value_2 = "StringValue" config_param_datatype_2 = str config_param_name_3 = "testParam3" config_param_value_3 = 1000 config_param_datatype_3 = "int32" config_param_name_4 = "testParam3_2" config_param_value_4 = 2000 config_param_datatype_4 = int config_param_name_5 = "testParam5" config_param_value_5 = 3.3 config_param_datatype_5 = float config_param_name_6 = "testParam6" config_param_value_6 = 3.3 config_param_datatype_6 = "float" config_param_name_7 = "testParam7" config_param_value_7 = datetime.datetime.now() config_param_datatype_7 = "date-time" myMsbClient.addConfigParameter(config_param_name_1, config_param_value_1, config_param_datatype_1) myMsbClient.addConfigParameter(config_param_name_2, config_param_value_2, config_param_datatype_2) myMsbClient.addConfigParameter(config_param_name_3, config_param_value_3, config_param_datatype_3) myMsbClient.addConfigParameter(config_param_name_4, config_param_value_4, config_param_datatype_4) myMsbClient.addConfigParameter(config_param_name_5, config_param_value_5, config_param_datatype_5) myMsbClient.addConfigParameter(config_param_name_6, config_param_value_6, config_param_datatype_6) myMsbClient.addConfigParameter(config_param_name_7, config_param_value_7, config_param_datatype_7) logging.debug("Self Description - added config params") # add events to the client: as single param myMsbClient.addEvent( "SIMPLE_EVENT1_STRING", "Simple event 1", "Simple event with string", DataType.STRING, "LOW", False, ) myMsbClient.addEvent( "SIMPLE_EVENT2_INTEGER_ARRAY", "Simple event 2", "Simple event with integer array", DataType.INT32, 0, True ) myMsbClient.addEvent( "SIMPLE_EVENT3_JSONDATAFORMAT", "Simple event 3", "Simple event with JSON stringified dataformat", '{ "type": "number", "format": "float" }', 2, False ) myMsbClient.addEvent( "SIMPLE_EVENT4_NOPAYLOAD", "Simple event 4", "Simple event with no payload", None, 0, False ) myMsbClient.addEvent( "DATE_EVENT", "Date Event", "Simple event with datetime", DataType.DATETIME, 0, False ) myMsbClient.addEvent( "arrayev", "Array Event", "Array Event for testing", DataType.STRING, "LOW", True ) # add events to the client: as event object event1 = Event( "EVENT1", "Event 1", "Event with string", DataType.STRING, "LOW", False ) myMsbClient.addEvent(event1) event1 = Event( "EVENT2", "Event 2", "Event with number", DataType.FLOAT, "LOW", False ) myMsbClient.addEvent(event1) logging.debug("Self Description - added simple events") # define properties for complex data format to be used in an event complexObject_name_1 = "ComplexObject1" complexObject_property_name_1 = "megaprop" complexObject_isArray_1 = False complexObject_name_2 = "ComplexObject2" complexObject_property_name_2 = "superprop" complexObject_isArray_2 = True complexObject_name_3 = "ComplexObject3" complexObject_property_name_3 = "mediumprop" complexObject_isArray_3 = True complexObject_name_4 = "ComplexObject4" complexObject_property_name_4 = "prop" complexObject_datatype_4 = "int32" complexObject_isArray_4 = True # initialize the complex data format complexObject_1 = ComplexDataFormat(complexObject_name_1) complexObject_2 = ComplexDataFormat(complexObject_name_2) complexObject_3 = ComplexDataFormat(complexObject_name_3) complexObject_4 = ComplexDataFormat(complexObject_name_4) # add properties to the nested complex data formats complexObject_4.addProperty( complexObject_property_name_4, complexObject_datatype_4, complexObject_isArray_4 ) complexObject_3.addProperty( complexObject_property_name_3, complexObject_4, complexObject_isArray_3 ) complexObject_2.addProperty( complexObject_property_name_2, complexObject_3, complexObject_isArray_2 ) complexObject_1.addProperty( complexObject_property_name_1, complexObject_2, complexObject_isArray_1 ) # add the event with the complex data format myMsbClient.addEvent( "EVENT3_COMPLEX", "Event 3 Complex Data Format", "Event wit a 4-level complex data format", complexObject_1, 0, True, ) # the final data format can be provided as a valid JSON object myMsbClient.addEvent( "COMPLEX_JSON_EVENT", "JSON based event", "JSON based event description", { "Member" : { "type" : "object", "properties" : { "name" : { "type" : "string" }, "status" : { "enum" : [ "present", "absent" ], "type" : "string" } } }, "Team" : { "type" : "object", "properties" : { "staff" : { "type" : "array", "items" : { "$ref" : "#/definitions/Member" } } } }, "dataObject" : { "$ref" : "#/definitions/Team" } }, 0, False, ) logging.debug("Self Description - added complex events") # define the function which will be passed to the function description def printMsg(msg): print(str(msg["dataObject"])) # add functions to the client: as single param myMsbClient.addFunction( "FUNCTION1", "Function 1", "Description function 1", "int32", printMsg, False, ["EVENT1", "EVENT2"], ) # add functions to the client: as function object function2 = Function( "FUNCTION2", "Function 2", "Description function 2", str, printMsg, False, ["EVENT1", "EVENT2"], ) myMsbClient.addFunction(function2) # the final data format can be provided as a valid JSON object myMsbClient.addFunction( "COMPLEX_JSON_FUNCTION", "Function JSON based", "Description function JSON based", { "Member" : { "type" : "object", "properties" : { "name" : { "type" : "string" }, "status" : { "enum" : [ "present", "absent" ], "type" : "string" } } }, "Team" : { "type" : "object", "properties" : { "staff" : { "type" : "array", "items" : { "$ref" : "#/definitions/Member" } } } }, "dataObject" : { "$ref" : "#/definitions/Team" } }, printMsg, False, ["EVENT1", "EVENT2"], ) # define the function which will be passed to the function description def arrayfun_implementation(msg): logging.debug("Array Function has been called, message: " + str(msg["a"])) global receivedArrayEvIndexCheck receivedArrayEvIndexCheck = True receivedArrayEvIndexCheck = str(msg["a"][0]) == "Hello" receivedArrayEvIndexCheck = str(msg["a"][1]) == "World" receivedArrayEvIndexCheck = str(msg["a"][2]) == "!" logging.debug( "Array Function has been called, correlationId: " + msg["correlationId"] ) global receivedArrayEvWithCorrectCorrelationId receivedArrayEvWithCorrectCorrelationId = ( str(msg["correlationId"]) == CORRELATIOON_ID_FOR_TEST ) global receivedArrayEv receivedArrayEv = True # add the function to be tested in integration flow function_arrayfun = Function( "/arrayfun", "Array Function", "Array Function for testing", str, arrayfun_implementation, True, None, ) myMsbClient.addFunction(function_arrayfun) logging.debug("Self Description - added functions")
from msb_client.TypeDescriptor import TypeDescriptor from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "Application" SO_UUID = "d654571c-4d4d-4b74-80a0-22771494cb39" SO_NAME = "Verification Service 1" SO_DESCRIPTION = "Verification Service 1" SO_TOKEN = "22771494cb39" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) msb_url = "wss://192.168.0.67:8084" myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableHostnameVerification(True)
from msb_client.TypeDescriptor import TypeDescriptor from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "SmartObject" SO_UUID = "2cfa27f4-f19d-4244-8bd9-b91d4d70ad3c" SO_NAME = "MSBClientPythonAppSample" + SO_UUID[-6:] SO_DESCRIPTION = "MSBClientPythonAppSample description" SO_TOKEN = "b91d4d70ad3c" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) # otherwise the application.properties file will be read # myMsbClient = MsbClient() msb_url = "wss://192.168.0.138:8084" # msb_url = 'wss://localhost:8084' # msb_url = 'ws://localhost:8085' # msb_url = 'ws://ws2.msb.edu.virtualfortknox.de' # enable debug log messages (default = disabled). myMsbClient.enableDebug(True) # enable ws lib trace console output (default = disabled).
from msb_client.Event import Event from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "SmartObject" SO_UUID = str(uuid.uuid1()) SO_NAME = "MSBClientPythonAppSample" + SO_UUID[-6:] SO_DESCRIPTION = "MSBClientPythonAppSample description" SO_TOKEN = SO_UUID[-6:] myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) # otherwise the application.properties file will be read # myMsbClient = MsbClient() # msb_url = 'wss://localhost:8084' # msb_url = 'ws://localhost:8085' msb_url = 'ws://ws2.msb.edu.virtualfortknox.de' # enable debug log messages (default = disabled). myMsbClient.enableDebug(True) # enable ws lib trace console output (default = disabled). myMsbClient.enableTrace(False)
from msb_client.Function import Function from msb_client.MsbClient import MsbClient if __name__ == "__main__": # app.run(host="0.0.0.0", port=1337) """This is a sample client for the MSB python client library.""" # define service properties as constructor parameters SERVICE_TYPE = "Application" SO_UUID = "af71d1ad-a2b9-4fd7-a450-ef8b7c72b107" SO_NAME = "Authentication Service" SO_DESCRIPTION = "CPPS Authentication Service" SO_TOKEN = "ef8b7c72b107" myMsbClient = MsbClient( SERVICE_TYPE, SO_UUID, SO_NAME, SO_DESCRIPTION, SO_TOKEN, ) myMsbClient.enableDebug(True) myMsbClient.enableTrace(False) myMsbClient.enableDataFormatValidation(True) myMsbClient.disableAutoReconnect(False) myMsbClient.setReconnectInterval(10000) myMsbClient.disableEventCache(False) myMsbClient.setEventCacheSize(1000) myMsbClient.disableHostnameVerification(True) myMsbClient.enableThreadAsDaemon(False) owner_uuid = "7c328ad1-cea5-410e-8dd8-6c7ca5a2e4f5"