Skip to content
Snippets Groups Projects
Commit 6bafe9f5 authored by Jan Rinze Peterzon's avatar Jan Rinze Peterzon
Browse files

Task #8571: added ToUpper service and clients in dir examples

parent c0d02f13
No related branches found
No related tags found
No related merge requests found
...@@ -2545,6 +2545,9 @@ LCS/MessageBus/python/common/CMakeLists.txt -text ...@@ -2545,6 +2545,9 @@ LCS/MessageBus/python/common/CMakeLists.txt -text
LCS/MessageBus/python/common/__init__.py -text LCS/MessageBus/python/common/__init__.py -text
LCS/MessageBus/python/common/factory.py -text LCS/MessageBus/python/common/factory.py -text
LCS/MessageBus/python/common/util.py -text LCS/MessageBus/python/common/util.py -text
LCS/MessageBus/python/examples/ToUpperClient -text
LCS/MessageBus/python/examples/ToUpperMapClient -text
LCS/MessageBus/python/examples/ToUpperService -text
LCS/MessageBus/python/messaging/CMakeLists.txt -text LCS/MessageBus/python/messaging/CMakeLists.txt -text
LCS/MessageBus/python/messaging/RPC.py -text LCS/MessageBus/python/messaging/RPC.py -text
LCS/MessageBus/python/messaging/Service.py -text LCS/MessageBus/python/messaging/Service.py -text
......
#!/usr/bin/python
from messaging.RPC import RPC
# Simple RPC client for Service 'ToUpper'
# Used settings
ServiceName="ToUpper"
BusName="simpletest"
NumRequests=10
Test="Hello World ToUpper "
# Initialize a Remote Procedure Call object
RPCService=RPC(BusName,ServiceName,timeout=10)
# 'with' tells the RPC object to connect to the bus
with RPCService:
for requestnr in range(NumRequests):
# execute the RPC Service
replymessage=RPCService(Test+str(requestnr))
# show the result from the RPC client
print replymessage
#!/usr/bin/python
#from messagebus.RPC import RPC
from messaging.RPC import RPC
# Simple RPC client for Service 'ToUpper'
# Used settings
ServiceName="ToUpper"
BusName="simpletest"
NumRequests=10
Test={}
Test["One"]="Hello World ToUpper"
Test["Two"]="Bla "
RPCService=RPC(BusName,ServiceName,timeout=10)
# loop forever
with RPCService:
for requestnr in range(NumRequests):
# send to the RPC Service
Test["sequence"]="nr:"+str(requestnr)
replymessage=RPCService(Test)
# show the result from the RPC client
print replymessage
#!/usr/bin/python
from messaging.Service import Service
# Simple RPC server 'ToUpper'
# create service function:
def ToUpper( Text ):
if (isinstance(Text,dict)):
ret={}
for name,value in Text.iteritems():
ret[name]=str(value).upper()
return ret
if (isinstance(Text,str)):
print "ToUpper : %s" %(Text)
return str(Text).upper()
ret="Failed to convert to upper"
try:
ret="Cannot conver to upper object:" + str(Text)
except Exception as e:
ret="Cannot conver to upper object:" + str(e)
return ret
# Used settings
ServiceName="ToUpper"
BusName="simpletest"
# Register function as a service handler listeneing at Bus BusName and ServiceName
myserv = Service(BusName,ServiceName,ToUpper,numthreads=4)
# 'with' sets up the connection context and defines the scope of the service.
with myserv:
# Start listening in the background. This will start as many threads as defined by the instance
myserv.StartListening()
# wait for control-C or kill
myserv.WaitForInterrupt()
# Tell all background listener threads to stop and wait for them to finish.
myserv.StopListening()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment