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)
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.º 5
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')
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.º 7
0
# coding=utf-8
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig, MulticastRegistry


__author__ = 'caozupeng'


if __name__ == '__main__':
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.ofpay.demo.api.UserProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用
    # registry = ZookeeperRegistry('192.168.59.103: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.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')

        except DubboClientError, client_error:
            print client_error
        time.sleep(5)
Exemplo n.º 8
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.º 9
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
 See the License for the specific language governing permissions and
 limitations under the License.

"""
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig

__author__ = 'caozupeng'

if __name__ == '__main__':

    service_interface = 'com.clife.robot.service.interfaces.ForBigDataFacadeService'
    config = ApplicationConfig('clife-business-robot')
    registry = ZookeeperRegistry('200.200.200.55:2181',
                                 config,
                                 version='2.5.3',
                                 group='/clife-v4')
    user_provider = DubboClient(service_interface,
                                registry,
                                version='2.5.3',
                                group='/clife-v4')
    for i in range(1000):
        try:
            print(user_provider.getDevicesInfoByBoxMac('10D07A764E1F'))
        except DubboClientError:
            print('error')
        except ConnectionError:
            print('error')
        time.sleep(5)
     http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

"""
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig


if __name__ == '__main__':
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.qianmi.kstore.provider.CustomerAddressProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用
    registry = ZookeeperRegistry('zookeeper:2181', config)
    # registry = MulticastRegistry('224.5.6.7:1234', config)
    user_provider = DubboClient(service_interface, registry, version='1.0')
    for i in range(1000):
        try:
            print user_provider.findAddressByCustomerId(1)
            # print user_provider.save(1, 3)

        except DubboClientError, client_error:
            print client_error.message
            print client_error.data
        time.sleep(5)
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

"""
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig

if __name__ == '__main__':
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.qianmi.kstore.provider.CustomerAddressProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用
    registry = ZookeeperRegistry('zookeeper:2181', config)
    # registry = MulticastRegistry('224.5.6.7:1234', config)
    user_provider = DubboClient(service_interface, registry, version='1.0')
    for i in range(1000):
        try:
            print user_provider.findAddressByCustomerId(1)
            # print user_provider.save(1, 3)

        except DubboClientError, client_error:
            print client_error.message
            print client_error.data
        time.sleep(5)
Exemplo n.º 13
0
# -*- encoding:utf-8 -*-
from dubbo_client import ApplicationConfig, ZookeeperRegistry, DubboClient

__author__ = 'bida'

if __name__ == '__main__':
    config = ApplicationConfig('consumer-of-helloworld-app')

    registry = ZookeeperRegistry('127.0.0.1:20880', config)
    service_interface = 'com.bernie.DemoService'
    service_provider = DubboClient(service_interface, registry, version='2.5.3')
    print service_provider.sayHello(u'bernie')
Exemplo n.º 14
0
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

"""
import time

from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig

__author__ = 'caozupeng'

if __name__ == '__main__':
    service_interface = 'com.clife.bigdate.service.CityDubboService'
    config = ApplicationConfig('clife-bigdata-business-scene')
    registry = ZookeeperRegistry('200.200.200.55:2181',
                                 config,
                                 version='2.5.3',
                                 group='/clife-v4')
    user_provider = DubboClient(service_interface,
                                registry,
                                version='2.5.3',
                                group='/clife-v4')
    #(user_provider.findCityByName('A003'))
Exemplo n.º 15
0
from dubbo_client import ZookeeperRegistry, DubboClient, DubboClientError, ApplicationConfig, MulticastRegistry

__author__ = 'caozupeng'
"""
通过zookeeper发现服务端,然后进行测试调用
"""
if __name__ == '__main__':
    # 等待注册的服务上线
    time.sleep(5)
    config = ApplicationConfig('test_rpclib')
    service_interface = 'com.ofpay.demo.api.UserProvider'
    # 该对象较重,有zookeeper的连接,需要保存使用,“zookeeper”是hostname
    registry = ZookeeperRegistry('127.0.0.1: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:
            # 获取A003编号的用户信息
            print user_provider.getUser('A003')
            # 获取用户ID为123的用户信息
            print user_provider.getUser(123)
            # 根据给定的一系列条件,json查询字符串查询用户信息
            print user_provider.queryUser({
                u'age': 18,
                u'time': 1428463514153,
                u'sex': u'MAN',
                u'id': u'A003',
                u'name': u'zhangsan'
            })
Exemplo n.º 16
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.º 17
0
#!usr/bin/env python  
# -*- coding:utf-8 -*-

""" 
@author: jayzhen
@email: [email protected]
@site: https://github.com/gitjayzhen
@software: PyCharm & Python 2.7
@file: DubboClientTest.py
@time: 2018/09/14 12:25 
"""
import time
from dubbo_client import ApplicationConfig, ZookeeperRegistry, DubboClient
from dubbo_client import DubboClientError

config = ApplicationConfig('test_rpclib')
service_interface = "com.auto.Interface.*"
# registry包含了和zookeeper的连接,该对象需要缓存
registry = ZookeeperRegistry('*.*.*.*:2181', config)
print registry.get_provides(service_interface)
user_provider = DubboClient(service_interface, registry, version='2.5.3')
for i in range(100):
        print user_provider("getAllfunctioninfo")

        time.sleep(5)