
本文共 5504 字,大约阅读时间需要 18 分钟。
Apache Dubbo ������������������
������������
��������������� Dubbo ������������������������������������Apache Dubbo ������������������������������������������������������������������������������������ Dubbo 2.7.0 ������������������������������������������������������
Dubbo ������������������������������������������������������������������������������������ RPC ��������������������������������������������� Spring ���������������������Dubbo ���������������������������������������������������������������������������������������������������������������������������������
������Dubbo ������������
Dubbo ������������������������������������������
������������������
- ������������������������������������������������������������
- ������������������������������������������������������������������������
- ���������������������������������������������������������������
- ���������������������������������������������������������������������������
- ���������������������������������������������������������������������������������������
- ������������������������������������������������������������������������������������
������������������������
1. Dubbo ��� Spring ������������
Dubbo ��� Spring ������������������������ Dependency Injection��������������������� AOP���������������������������
2. ������������������
��������������������������� Dubbo ���������������������������������
public interface GreetingService { String sayHello(String name); CompletableFuturesayHelloForAsync(String name); String sayHelloForAsyncByContext(String name);}public class GreetingServiceImpl implements GreetingService { private static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(8, 15, 1, TimeUnit.MINUTES, new SynchronousQueue<>(), new NamedThreadFactory("thread-pool"), new CallerRunsPolicy()); // ������������������������������������}
���������������������������
4.1 ���������������
��������������������� ServiceConfig
������������������������
public class ApiProvider { public static void main(String[] args) throws IOException { ServiceConfig serviceServiceConfig = new ServiceConfig(); serviceServiceConfig.setApplication(new ApplicationConfig("Api-provider")); serviceServiceConfig.setRegistry(new RegistryConfig("zookeeper://localhost:2181")); serviceServiceConfig.setInterface(GreetingService.class); serviceServiceConfig.setRef(new GreetingServiceImpl()); serviceServiceConfig.export(); System.out.println("���������������"); System.in.read(); }}
4.2 ���������������
��������������������� ReferenceConfig
������������������������������
public class ApiConsumer { public static void main(String[] args) { ReferenceConfig referenceConfig = new ReferenceConfig(); referenceConfig.setRegistry(new RegistryConfig("zookeeper://localhost:2181")); referenceConfig.setTimeout(5000); GreetingService greetingService = referenceConfig.get(); // ��������������������������� RpcContext.getContext().setAttachment("attribute", "ApiConsumer"); String hello = greetingService.sayHello("hello"); System.out.println("hello = " + hello); }}
������������������������
5.1 ������������
������������������������������������������������������������������������������
5.2 ������������
���������������������������������������
whenComplete
������������������������������������
Dubbo ������������������������������������
���������������������������������������������������������
public class ApiGenericConsumer { public static void main(String[] args) throws IOException, ClassNotFoundException { ReferenceConfig referenceConfig = new ReferenceConfig(); referenceConfig.setTimeout(5000); referenceConfig.setRegistry(new RegistryConfig("zookeeper://localhost:2181")); referenceConfig.setGeneric(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA); GenericService genericService = referenceConfig.get(); // ������������������������������ ExtensionLoader projLoader = ExtensionLoader.getExtensionLoader(Serialization.class); projLoader.ExtensionConstants.GENERIC_SERIALIZATION_NATIVE_JAVA .getExtension() .serialize(null, new ByteArrayOutputStream()) .writeObject("������"); Object result = projLoader.ExtensionConstants.GENERIC_SERIALIZATION_NATIVE_JAVA .getExtension() .deserialize(null, new ByteArrayInputStream(resultBytes.toByteArray())); System.out.println("���������������" + result); }}
������������������
Dubbo ���������������������������
������������������������������mock���������
referenceConfig.setMock(true);
��������������������������������������� Dubbo ������������������������������������������������������������������������������������������������Apache Dubbo ������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
