Search in sources :

Example 1 with DemoService

use of com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService in project Sentinel by alibaba.

the class DemoConsumer method main.

public static void main(String[] args) throws Exception {
    ApplicationConfig application = new ApplicationConfig().setAppName("DemoConsumer");
    ConsumerConfig<DemoService> consumerConfig = new ConsumerConfig<DemoService>().setApplication(application).setInterfaceId(DemoService.class.getName()).setProtocol("bolt").setDirectUrl("bolt://127.0.0.1:12001").setInvokeType(RpcConstants.INVOKER_TYPE_SYNC);
    // 设置是否启用Sentinel,默认启用
    // 也可在rpc-config.json全局设置
    // consumerConfig.setParameter("sofa.rpc.sentinel.enabled", "false");
    DemoService helloService = consumerConfig.refer();
    System.out.println("DemoConsumer started!");
    long sleepMs = 5;
    int total = 5000;
    int index = 0;
    System.out.println("Total call " + total + " times and sleep " + sleepMs + "ms after each call.");
    while (true) {
        try {
            index++;
            String result = helloService.sayHello(index, "SOFARPC", 2020);
            System.out.println("[" + index + "][Consumer]receive response: " + result);
        } catch (Exception e) {
            System.out.println("[" + index + "][Consumer]receive exception: " + e.getMessage());
        }
        TimeUnit.MILLISECONDS.sleep(sleepMs);
        if (index == total) {
            break;
        }
    }
    System.out.println("DemoConsumer exit!");
    System.exit(0);
}
Also used : ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) DemoService(com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService)

Example 2 with DemoService

use of com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService in project Sentinel by alibaba.

the class DemoProvider method main.

public static void main(String[] args) {
    ServerConfig serverConfig = new ServerConfig().setProtocol("bolt").setPort(12001).setDaemon(false);
    ProviderConfig<DemoService> providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setServer(serverConfig);
    // 设置是否启用Sentinel,默认启用
    // 也可在rpc-config.json全局设置
    // providerConfig.setParameter("sofa.rpc.sentinel.enabled", "false");
    providerConfig.export();
    System.out.println("DemoProvider started!");
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) DemoService(com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService) DemoServiceImpl(com.alibaba.csp.sentinel.demo.sofa.rpc.service.impl.DemoServiceImpl)

Aggregations

DemoService (com.alibaba.csp.sentinel.demo.sofa.rpc.service.DemoService)2 DemoServiceImpl (com.alibaba.csp.sentinel.demo.sofa.rpc.service.impl.DemoServiceImpl)1 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1