Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
103 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,29 @@ | ||
#encoding=utf-8 | ||
from urlparse import urlparse, parse_qsl | ||
|
||
__author__ = 'caozupeng' | ||
|
||
|
||
class ServiceProvider(object): | ||
protocol = 'jsonrpc' | ||
location = '' # ip+port | ||
path = '' # like /com.qianmi.dubbo.UserProvider | ||
ip = '127.0.0.1' | ||
port = '9090' | ||
|
||
def __init__(self, url): | ||
result = urlparse(url) | ||
self.protocol = result[0] | ||
self.location = result[1] | ||
self.path = result[2] | ||
if self.location.find(':') > -1: | ||
self.ip, self.port = result[1].split(':') | ||
params = parse_qsl(result[4]) | ||
for key, value in params: | ||
# url has a default.timeout property, but it can not add in python object | ||
# so keep the last one | ||
pos = key.find('.') | ||
if pos > -1: | ||
key = key[pos + 1:] | ||
print key | ||
self.__dict__[key] = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,13 +1,19 @@ | ||
# coding=utf-8 | ||
import time | ||
|
||
from dubbo_client import DubboClient | ||
|
||
|
||
__author__ = 'caozupeng' | ||
|
||
if __name__ == '__main__': | ||
service_interface = 'com.ofpay.demo.api.UserProvider' | ||
dubbo_client = DubboClient(service_interface) | ||
print dubbo_client.getUser('A003') | ||
print dubbo_client.queryUser( | ||
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'}) | ||
print dubbo_client.queryAll() | ||
print dubbo_client.isLimit('MAN', 'Joe') | ||
for i in range(1000): | ||
print dubbo_client.getUser('A003') | ||
print dubbo_client.queryUser( | ||
{u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'}) | ||
print dubbo_client.queryAll() | ||
print dubbo_client.isLimit('MAN', 'Joe') | ||
print dubbo_client('getUser', 'A005') | ||
time.sleep(5) |