Skip to content

Commit

Permalink
Sidecar example for python
Browse files Browse the repository at this point in the history
  • Loading branch information
Asim committed May 30, 2016
1 parent 3a42d97 commit 79b1131
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions examples/greeter/server/python/sidecar_server.py
@@ -0,0 +1,35 @@
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
from jsonrpc import JSONRPCResponseManager, dispatcher

import uuid
import requests
import json

def register():
register_uri = "http://localhost:8081/registry"
service = "go.micro.srv.greeter"
headers = {'content-type': 'application/json'}
payload = {
"name": service,
"nodes": [{
"id": service + "-" + str(uuid.uuid4()),
"address": "127.0.0.1",
"port": 4000,
}],
}
requests.post(register_uri, data=json.dumps(payload), headers=headers)

@Request.application
def application(request):
# Dispatcher is dictionary {<method_name>: callable}
dispatcher["Say.Hello"] = lambda s: "hello " + s["name"]

response = JSONRPCResponseManager.handle(
request.data, dispatcher)
return Response(response.json, mimetype='application/json')


if __name__ == '__main__':
register()
run_simple('localhost', 4000, application)

0 comments on commit 79b1131

Please sign in to comment.