Example of dubbo direct connection code and dubbo code
We all know that dubbo is a distributed RPC tool. If we have time to allow it, we will write down dubbo. When we call or want to specify a machine for execution in the test environment, it does not require scheduling tools such as ZK. dubbo also provides the configuration solution. It is very simple to specify the URL, but this is not recorded here, it is called directly through code. This is recorded here. Let's talk about the code.
ApplicationConfig applicationConfig = new ApplicationConfig(); applicationConfig.setName("mix"); ReferenceConfig<TaskExecutor> referenceConfig = new ReferenceConfig<TaskExecutor>(); referenceConfig.setInterface("com.*.TaskExecutor"); referenceConfig.setUrl("dubbo://127.0.0.1:20880/com.*.TaskExecutor"); referenceConfig.setApplication(applicationConfig); MethodConfig methodConfig = new MethodConfig(); methodConfig.setName("executeTask"); methodConfig.setAsync(false); referenceConfig.setMethods(Arrays.asList(new MethodConfig[]{methodConfig})); System.out.println(referenceConfig.get().executeTask(bean)); }
Com. *. taskExecutor is the full name of the interface, "dubbo: // 127.0.0.1: 20880/com. *. taskExecutor "is the service address," executeTask "is the method name, and bean is the method parameter.