Search in sources :

Example 1 with ServiceB

use of com.alipay.sofa.rpc.asynchain.ServiceB in project sofa-rpc by sofastack.

the class ServerB method main.

public static void main(String[] args) {
    // B服务里的C服务客户端
    ConsumerConfig<ServiceC> consumerConfig = new ConsumerConfig<ServiceC>().setApplication(new ApplicationConfig().setAppName("BBB")).setInterfaceId(ServiceC.class.getName()).setDirectUrl("bolt://127.0.0.1:12299?appName=CCC").setRegister(false).setInvokeType(// 不设置,调用级别可设置
    "callback").setTimeout(2000);
    ServiceC serviceC = consumerConfig.refer();
    ServerConfig serverConfig = new ServerConfig().setPort(12298).setDaemon(false);
    ProviderConfig<ServiceB> providerConfig = new ProviderConfig<ServiceB>().setInterfaceId(ServiceB.class.getName()).setApplication(new ApplicationConfig().setAppName("BBB")).setRef(new ServiceBImpl(serviceC)).setServer(serverConfig).setRegister(false);
    providerConfig.export();
}
Also used : ServiceC(com.alipay.sofa.rpc.asynchain.ServiceC) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ServiceB(com.alipay.sofa.rpc.asynchain.ServiceB) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ServiceBImpl(com.alipay.sofa.rpc.asynchain.ServiceBImpl) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 2 with ServiceB

use of com.alipay.sofa.rpc.asynchain.ServiceB in project sofa-rpc by sofastack.

the class ClientA method main.

public static void main(String[] args) {
    // A 服务
    ConsumerConfig<ServiceB> consumerConfig = new ConsumerConfig<ServiceB>().setApplication(new ApplicationConfig().setAppName("AAA")).setInterfaceId(ServiceB.class.getName()).setDirectUrl("bolt://127.0.0.1:12298?appName=BBB").setRegister(false).setTimeout(3000);
    ServiceB serviceB = consumerConfig.refer();
    while (true) {
        try {
            int ret0 = serviceB.getInt(999);
            LOGGER.info("ret0:" + ret0);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Thread.sleep(3000);
        } catch (Exception e) {
        }
    }
}
Also used : ServiceB(com.alipay.sofa.rpc.asynchain.ServiceB) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig)

Aggregations

ServiceB (com.alipay.sofa.rpc.asynchain.ServiceB)2 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)2 ServiceBImpl (com.alipay.sofa.rpc.asynchain.ServiceBImpl)1 ServiceC (com.alipay.sofa.rpc.asynchain.ServiceC)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1