diff --git a/example/src/main/java/com/alibaba/nacos/example/NamingExample.java b/example/src/main/java/com/alibaba/nacos/example/NamingExample.java index db5d885a6..ef58a968c 100644 --- a/example/src/main/java/com/alibaba/nacos/example/NamingExample.java +++ b/example/src/main/java/com/alibaba/nacos/example/NamingExample.java @@ -55,25 +55,23 @@ public class NamingExample { NamingService naming = NamingFactory.createNamingService(properties); naming.registerInstance(INSTANCE_SERVICE_NAME, INSTANCE_IP, INSTANCE_PORT, INSTANCE_CLUSTER_NAME); - - System.out.println("[instances after register] " + naming.getAllInstances(INSTANCE_SERVICE_NAME)); - + Executor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), runnable -> { Thread thread = new Thread(runnable); thread.setName("test-thread"); return thread; }); - + naming.subscribe(INSTANCE_SERVICE_NAME, new AbstractEventListener() { - + //EventListener onEvent is sync to handle, If process too low in onEvent, maybe block other onEvent callback. //So you can override getExecutor() to async handle event. @Override public Executor getExecutor() { return executor; } - + @Override public void onEvent(Event event) { System.out.println("[serviceName] " + ((NamingEvent) event).getServiceName()); @@ -81,8 +79,14 @@ public class NamingExample { } }); - naming.deregisterInstance(INSTANCE_SERVICE_NAME, INSTANCE_IP, INSTANCE_PORT, INSTANCE_CLUSTER_NAME); + Thread.sleep(1000); + + System.out.println("[instances after register] " + naming.getAllInstances(INSTANCE_SERVICE_NAME)); + Thread.sleep(1000); + + naming.deregisterInstance(INSTANCE_SERVICE_NAME, INSTANCE_IP, INSTANCE_PORT, INSTANCE_CLUSTER_NAME); + Thread.sleep(1000); System.out.println("[instances after deregister] " + naming.getAllInstances(INSTANCE_SERVICE_NAME)); diff --git a/example/src/main/resources/logback.xml b/example/src/main/resources/logback.xml new file mode 100644 index 000000000..ddf83b60b --- /dev/null +++ b/example/src/main/resources/logback.xml @@ -0,0 +1,52 @@ + + + + + + + + + /Users/xiweng.yy/logs/nacos/perf.log + + + /Users/xiweng.yy/logs/nacos/perf.log.%i + ${JM.LOG.RETAIN.COUNT:-7} + + + + ${JM.LOG.FILE.SIZE:-10MB} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n + + + + + + + + + + + + + + + + +