示例#1
0
 def registService(self,
                   serviceName: str,
                   port=80,
                   address=None,
                   ttl=30,
                   degisterAfter='1m'):
     params = {'Name': serviceName, 'Port': port}
     if address:
         params['Address'] = address
     else:
         params['Address'] = local_ip()
     params['ID'] = self.genInstanceID(serviceName, params['Address'], port)
     '''
     params['Check'] = {
         'Interval' : "%ss" % checkInterval,
         'DeregisterCriticalServiceAfter' : '1m',
         'Timeout' : '5s',
         'TCP' : "%s:%s" % (params['Address'], port)
     }
     '''
     params['Check'] = {
         'DeregisterCriticalServiceAfter': degisterAfter,
         'TTL': '%ss' % ttl,
     }
     print('params', json.dumps(params))
     url = self.baseUrl + '/v1/agent/service/register'
     r = requests.put(url, data=json.dumps(params), timeout=self.timeout)
     print(r.text, r.status_code)
示例#2
0
 def create_server():
     disconf = DiscoveryConfig(consulHost=CONSUL_HOST,
                               consulPort=CONSUL_PORT,
                               serviceName='test-udp-rpc-server',
                               serviceHost=local_ip(),
                               servicePort=10002)
     server = UdpRpcServer('0.0.0.0', 10002)
     server.setDiscoverConfig(disconf)
     server.regist(sayHello)
     server.serve()
示例#3
0
 def create_server():
     from agileutil.rpc.server import TcpRpcServer
     from agileutil.rpc.discovery import DiscoveryConfig
     disconf = DiscoveryConfig(consulHost=CONSUL_HOST,
                               consulPort=CONSUL_PORT,
                               serviceName='test-rpc-server',
                               serviceHost=local_ip(),
                               servicePort=10001)
     server = TcpRpcServer('0.0.0.0', 10001)
     server.setDiscoverConfig(disconf)
     server.regist(sayHello)
     server.serve()
示例#4
0
def create_http_server_discovery():
    if not IS_TEST_DISCOVERY: return
    server = HttpRpcServer('127.0.0.1', 10003)
    disconf = DiscoveryConfig(
        consulHost=CONSUL_HOST,
        consulPort=CONSUL_PORT,
        serviceName='test-http-rpc-server',
        serviceHost=local_ip(),
        servicePort=10003,
    )
    server.setDiscoverConfig(disconf)
    server.regist(sayHello)
    server.serve()
示例#5
0
def create_http_server_discovery():
    from agileutil.rpc.server import HttpRpcServer
    from agileutil.rpc.discovery import DiscoveryConfig
    server = HttpRpcServer('127.0.0.1', 10003)
    server.disableLog()
    disconf = DiscoveryConfig(
        consulHost=CONSUL_HOST,
        consulPort=CONSUL_PORT,
        serviceName='test-http-rpc-server',
        serviceHost=local_ip(),
        servicePort=10003,
    )
    server.setDiscoverConfig(disconf)
    server.regist(sayHello)
    server.serve()