Exemplo n.º 1
0
def my_zk():
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.yytcloud.platform.service.api.IApplicationQueryService'
    # 该对象较重,有zookeeper的连接,需要保存使用
    registry = ZookeeperRegistry('10.188.181.146:2181', config)
    # registry = MulticastRegistry('224.5.6.7:1234', config)
    user_provider = DubboClient(service_interface, registry, version='1.0.0',group='usertest_yytcloud_default')
    for i in range(1000):
        try:
            pk=user_provider.call("queryAllApplication")
            # pk = user_provider.queryCorpList()
            print(pk)
            # print(user_provider.getUserByCode('wuzq'))
            # print user_provider.getUser(123)
            # print user_provider.queryUser(
            #     {u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
            # datas = user_provider.queryAll()
            # for key, user in datas.items():
            #     print user['name']
            # print user_provider.isLimit('MAN', 'Joe')
            # print user_provider('getUser', 'A005')
            # print user_provider.notFunc()
            # print user_provider.gotException()
        except DubboClientError as client_error:
            print(client_error.message)
            print(client_error.data)
        time.sleep(5)
Exemplo n.º 2
0
 def test_something(self):
     application_name = 'test_rpclib'
     address = '224.5.6.7:1234'
     service = 'com.unj.dubbotest.provider.DemoService'
     config = Application(application_name)
     registry = MulticastRegistry(address)
     user_provider = DubboClient(service, registry)
     result = user_provider.sayHello('World')
     self.assertEqual(result, 'Hello World')
def test_config_init():
    config = ApplicationConfig('test_register_config')
    service_interface = 'com.ofpay.demo.api.UserProvider'
    registry = ZookeeperRegistry('172.19.66.49:2181', config)
    user_provider = DubboClient(service_interface, registry, version='1.0.0')
    for i in range(10000):
        try:
            print user_provider.findOne()
        except DubboClientError, client_error:
            print client_error
        time.sleep(1)
Exemplo n.º 4
0
def test_dubbo():
    service_interface = 'com.ofpay.demo.api.UserProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用
    registry = ZookeeperRegistry('172.19.65.33:2181')
    user_provider = DubboClient(service_interface, registry, version='2.0')
    for x in range(number):
        user_provider.getUser('A003')
        user_provider.queryUser(
            {u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
        # user_provider.queryAll()
        user_provider.isLimit('MAN', 'Joe')
        user_provider('getUser', 'A005')
Exemplo n.º 5
0
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig

__author__ = 'caozupeng'

if __name__ == '__main__':

    #config = ApplicationConfig('provider')
    #service_interface = 'com.jaycekon.dubbo.service.CityDubboService'

    config = ApplicationConfig('clife-bigdata-business-scene')
    service_interface = 'com.clife.bigdata.service.ai.sleep.SleepReportService'
    registry = ZookeeperRegistry('200.200.200.55:2181', config)
    user_provider = DubboClient(service_interface,
                                registry,
                                version='2.5.3',
                                group='/clife-v4')
    for i in range(1000):
        try:
            print user_provider.getSleepReport(139, 68265, "2019-05-13", 0)
            #print user_provider.findCityByName('A003')
            # print user_provider.getUser(123)
            # print user_provider.queryUser(
            #     {u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
            # datas = user_provider.queryAll()
            # for key, user in datas.items():
            #     print user['name']
            # print user_provider.isLimit('MAN', 'Joe')
            # print user_provider('getUser', 'A005')
            # print user_provider.notFunc()
            # print user_provider.gotException()
Exemplo n.º 6
0
    def handle_stream(self, stream, address):
        magic_number = yield stream.read_bytes(2)
        # gen_log.info('receive magic number success')
        if magic_number != '\xab\xcd':
            return
        interface_len = yield stream.read_bytes(4)
        interface_len = bytes2int(interface_len)
        gen_log.info('interface len: %d', interface_len)
        interface = yield stream.read_bytes(interface_len)
        gen_log.info('get interface: [%s]', interface)
        method_len = yield stream.read_bytes(4)
        method_len = bytes2int(method_len)
        method = yield stream.read_bytes(method_len)
        pts_len = yield stream.read_bytes(4)
        pts_len = bytes2int(pts_len)
        pts = yield stream.read_bytes(pts_len)
        channel_key = (interface, method, pts)
        gen_log.info('get method: [%s]', method)
        gen_log.info('get pts: [%s]', pts)
        if channel_key in self.dubbo_channel_map:
            dubbo_client = self.dubbo_channel_map[channel_key]
        else:
            dubbo_client = DubboClient('localhost', 20880)
            self.dubbo_channel_map[channel_key] = dubbo_client

        def make_request(Id):
            ar = ActRequest()
            ar.interface = interface
            ar.method = method
            ar.parameter_types_string = pts
            ar.Id = Id
            return ar

        def make_dubbo_request(act_request):
            dr = DubboRequest()
            dr.Id = act_request.Id
            # dr.Id = random.randint(1, 2100000000)
            dr.interface_name = act_request.interface
            dr.method_name = act_request.method
            # dr.dubbo_version = ''
            # dr.version = ''
            dr.args = act_request.parameter
            return dr

        def make_act_response(dubbo_response):
            aresp = ActResponse()
            aresp.Id = dubbo_response.Id
            aresp.result = dubbo_response.result
            return aresp

        while True:
            try:
                Id = yield stream.read_bytes(4)
                request = make_request(bytes2int(Id))
                p_len = yield stream.read_bytes(4)
                request.parameter = yield stream.read_bytes(bytes2int(p_len))
                gen_log.info("get request %d %s", request.Id, request.parameter)

                def callback(dubbo_response):
                    # gen_log.info("get dubbo_resp %d [%s] \nstream write act resp", dubbo_response.Id, dubbo_response.result)
                    stream.write(make_act_response(dubbo_response).encode_body())

                dubbo_client.fetch(make_dubbo_request(request), callback=callback)
            except StreamClosedError:
                break
Exemplo n.º 7
0
 limitations under the License.

"""
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig

__author__ = 'caozupeng'

if __name__ == '__main__':
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.ofpay.demo.api.UserProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用
    registry = ZookeeperRegistry('115.28.74.185:2181', config)
    # registry = MulticastRegistry('224.5.6.7:1234', config)
    user_provider = DubboClient(service_interface, registry, version='2.0')
    for i in range(1000):
        try:
            print user_provider.getUser('A003')
            # print user_provider.getUser(123)
            # print user_provider.queryUser(
            #     {u'age': 18, u'time': 1428463514153, u'sex': u'MAN', u'id': u'A003', u'name': u'zhangsan'})
            # datas = user_provider.queryAll()
            # for key, user in datas.items():
            #     print user['name']
            # print user_provider.isLimit('MAN', 'Joe')
            # print user_provider('getUser', 'A005')
            # print user_provider.notFunc()
            # print user_provider.gotException()
        except DubboClientError, client_error:
            print client_error.message