Dear Coeuz:
I think there must be something misunderstanding.
First thing, I always respect the God who create ZATO very much . (I mean Darisuz)
Because of his work, I can build my things rapidly.
I am coming for help. And I hope I can make ZATO more stronger and contribute something to it.
I am not coming for arguing or anything impolite.
I am not a Latin language user, I am not good at English. so some times I can not describe the problem clearly and hardly know what the tutorial means.
In these days , I did read tutorial once and once again.
I wrote the sample code , and make it became the service.
Just like the tutorial tells me to do . (writes the code , and configure it in webadmin)
I would like to show all the code here ,but it’s not easy to post codes here.
OK, I will show all the codes below,.
======================customer_broker.py==========================
-- coding: utf-8 --
from future import absolute_import, division, print_function, unicode_literals
import sys
import traceback
from zato.common.util import new_cid
from json import dumps, loads
from zato.common.broker_message import SERVICE
from zato.server.service import Service
###################################################################
Here is the access.
This class is the wrapper
###################################################################
class CustomerBroker(Service):
def handle(self):
self.logger.info(‘Customer Broker is called! cid = [{}]’.format(self.cid))
response = {}
payload = self.request.payload
payload[‘org_cid’] = self.cid
try:
if payload[‘method’] == ‘async’:
self.invoke_async(‘customer-engine.customer-engine’,payload)
response[‘cid’] = self.cid
response[‘ret’] = 'OK’
else:
response = eval(self.invoke(‘customer-engine.customer-engine’,payload))
response[‘cid’] = self.cid
except Exception:
exstr = traceback.format_exc()
self.logger.error(’[{}] '.format(exstr))
response[‘cid’] = self.cid
response[‘ret’] = 'SYS ERR’
response[‘info’] = ‘system error’
self.response.payload = dumps(response)
===============================customer_engine.py=================================
-- coding: utf-8 --
from future import absolute_import, division, print_function, unicode_literals
import sys
import traceback
from json import dumps, loads
from zato.server.service import Service
SUPPORTED_CMDS={
“reg”: “CustomerReg”,
“upd”: “CustomerUpdate”
}
class CustomerHandler:
def handle(self,request,response,service):
service.logger.info(‘Base was called, cid = {},org = {}’.format(service.cid,request[‘org_cid’]))
response[‘ret’] = 'OK’
response[‘cid’] = service.cid
class CustomerReg (CustomerHandler):
def handle(self,request,response,service):
service.logger.info(‘Reg was called, cid = {},org = {}’.format(service.cid,request[‘org_cid’]))
response[‘ret’] = 'OK’
response[‘cid’] = service.cid
class CustomerUpdate (CustomerHandler):
def handle(self,request,response,service):
service.logger.info(‘Update was called, cid = {}, org = {}’.format(service.cid,request[‘org_cid’]))
response[‘ret’] = 'OK’
response[‘cid’] = service.cid
###################################################################
Here is the access. Engine starts
This class is to find situable class to handle
###################################################################
class CustomerEngine(Service):
def handle(self):
response = {}
request = self.request.payload
try:
cmd = request[‘cmd’]
for k,v in SUPPORTED_CMDS.items() :
if cmd == k :
handler = globals()[v] ()
handler.handle( request,response,self)
response = dumps(response)
self.response.payload = response
return
self.logger.error(‘NO CLASS found, CMD = {}, cid = {}, org= {}’ . format(cmd,self.cid,request[‘org_cid’]) )
response[‘cid’] = self.cid
response[‘ret’] = 'ERROR’
response[‘info’] = ‘unknown cmd’
except Exception:
exstr = traceback.format_exc()
self.logger.error(’[{}] '.format(exstr))
response[‘ret’] = 'SYS ERR’
response[‘info’] = 'Unknown ERROR’
response[‘cid’] = self.cid
response = dumps(response)
self.response.payload = response
===============================customer_engine.py=================================
These codes run well except when I used SERVICE.PUBLISH to replace invoke_async in CustomerBroker.handle function
Maybe I made stupid things, but I am working hard. I just can not understand the tutorial very well.
If I do anything impolite , please forgive me.
And I will apologize for anything impolite.
Thanks.
Your sincerely
Kelvin
At 2014-11-19 17:09:37, “Coeuz” coeuz@coeuz.net wrote:
El 19/11/14 a les 02:13, Kelvin ha escrit:
It’s service. I just gave them a little wrapper.
Whoa, whoa…keep down that arrogance, man.
If you had read something in the Zato tutorial
(https://zato.io/docs/tutorial/01.html) or in the developing
documentation (https://zato.io/docs/progguide/service-dev.html) instead
of jumping directly into the code you would have read that “a service is
a Python class that subclasses zato.server.Service and implements a
handle(self) method”.
This is NOT the case, so no, this is NOT a service no matter how hard
you want to give it that name.
And, please, read some of the documentation, understand it and follow
the tutorial before coming here claiming to having found a bug or
something partially implemented.
In that case, if you are not trying to teach the guy who created all
this zato story (I mean Darisuz) what is a service and what is not and
you are open to learn it yourself instead, be sure that everyone here
will be very glad to share their knowledge with you to help you achieve
your objectives.
Regards,
Carles