Search in sources :

Example 1 with BlockException

use of com.alibaba.csp.sentinel.slots.block.BlockException in project rocketmq-externals by apache.

the class PullConsumerDemo method doSomething.

private static void doSomething(MessageExt message) {
    pool.submit(() -> {
        Entry entry = null;
        try {
            ContextUtil.enter(KEY);
            entry = SphU.entry(KEY, EntryType.OUT);
            // Your business logic here.
            System.out.printf("[%d][%s][Success: %d] Receive New Messages: %s %n", System.currentTimeMillis(), Thread.currentThread().getName(), SUCCESS_COUNT.addAndGet(1), new String(message.getBody()));
        } catch (BlockException ex) {
            // Blocked.
            System.out.println("Blocked: " + FAIL_COUNT.addAndGet(1));
        } finally {
            if (entry != null) {
                entry.exit();
            }
            ContextUtil.exit();
        }
    });
}
Also used : Entry(com.alibaba.csp.sentinel.Entry) BlockException(com.alibaba.csp.sentinel.slots.block.BlockException)

Aggregations

Entry (com.alibaba.csp.sentinel.Entry)1 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)1