Search in sources :

Example 1 with FooServiceConsumer

use of com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer in project Sentinel by alibaba.

the class FooConsumerBootstrap method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
    consumerContext.register(ConsumerConfiguration.class);
    consumerContext.refresh();
    FooServiceConsumer service = consumerContext.getBean(FooServiceConsumer.class);
    for (int i = 0; i < 15; i++) {
        try {
            String message = service.sayHello("Eric");
            System.out.println("Success: " + message);
        } catch (SentinelRpcException ex) {
            System.out.println("Blocked");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FooServiceConsumer(com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer) SentinelRpcException(com.alibaba.csp.sentinel.slots.block.SentinelRpcException) SentinelRpcException(com.alibaba.csp.sentinel.slots.block.SentinelRpcException)

Example 2 with FooServiceConsumer

use of com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer in project Sentinel by alibaba.

the class FooConsumerBootstrap method main.

public static void main(String[] args) {
    initFlowRule();
    AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
    consumerContext.register(ConsumerConfiguration.class);
    consumerContext.refresh();
    FooServiceConsumer service = consumerContext.getBean(FooServiceConsumer.class);
    for (int i = 0; i < 10; i++) {
        pool.submit(() -> {
            try {
                String message = service.sayHello("Eric");
                System.out.println("Success: " + message);
            } catch (SentinelRpcException ex) {
                System.out.println("Blocked");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        });
        pool.submit(() -> System.out.println("Another: " + service.doAnother()));
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) FooServiceConsumer(com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer) SentinelRpcException(com.alibaba.csp.sentinel.slots.block.SentinelRpcException) SentinelRpcException(com.alibaba.csp.sentinel.slots.block.SentinelRpcException)

Aggregations

FooServiceConsumer (com.alibaba.csp.sentinel.demo.dubbo.consumer.FooServiceConsumer)2 SentinelRpcException (com.alibaba.csp.sentinel.slots.block.SentinelRpcException)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2