From f487bb44ca58813a4123c32d28c1a8a90ebc4a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=A9?= <xiangsheng.gh@alibaba-inc.com> Date: Tue, 7 May 2019 14:36:49 +0800 Subject: [PATCH] Update consumer --- .../java/com/aliware/tianchi/MyConsumer.java | 37 +++++++------------ pom.xml | 6 ++- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java b/internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java index f69b0e2..e413e71 100644 --- a/internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java +++ b/internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java @@ -1,44 +1,35 @@ package com.aliware.tianchi; -import java.io.IOException; -import java.util.Collections; +import java.util.List; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; - -/** @author guohaoice@gmail.com */ +/** + * Gateway å¯åŠ¨å…¥å£ + * @author guohaoice@gmail.com */ public class MyConsumer { - public static void main(String[] args) throws IOException, InterruptedException { - // 当å‰åº”用é…ç½® + public static void main(String[] args) throws InterruptedException { ApplicationConfig application = new ApplicationConfig(); application.setName("service-gateway"); - // 连接注册ä¸å¿ƒé…ç½® + // 直连方å¼ï¼Œä¸ä½¿ç”¨æ³¨å†Œä¸å¿ƒ RegistryConfig registry = new RegistryConfig(); -// String address="com.aliware.tianchi.HashInterface-" -// +"localhost:20880_" -// +"localhost:20880"; -// registry.setAddress("list://localhost:9999"); registry.setAddress("N/A"); -// registry.setParameters(Collections.singletonMap(LIST_URL_KEY,address)); - - // 注æ„:ReferenceConfig为é‡å¯¹è±¡ï¼Œå†…部å°è£…了与注册ä¸å¿ƒçš„连接,以åŠä¸ŽæœåŠ¡æä¾›æ–¹çš„连接 - - // 引用远程æœåŠ¡ - ReferenceConfig<HashInterface> reference = - new ReferenceConfig<HashInterface>(); // æ¤å®žä¾‹å¾ˆé‡ï¼Œå°è£…了与注册ä¸å¿ƒçš„连接以åŠä¸Žæä¾›è€…的连接,请自行缓å˜ï¼Œå¦åˆ™å¯èƒ½é€ æˆå†…å˜å’Œè¿žæŽ¥æ³„æ¼ + ReferenceConfig<HashInterface> reference = new ReferenceConfig<>(); reference.setApplication(application); - reference.setRegistry(registry); // 多个注册ä¸å¿ƒå¯ä»¥ç”¨setRegistries() + reference.setRegistry(registry); reference.setInterface(HashInterface.class); -// reference.setUrl(new URL(Constants.DUBBO_PROTOCOL,"localhost",20880,reference.getInterface())); - reference.setUrl("localhost:20880"); - // 和本地beanä¸€æ ·ä½¿ç”¨xxxService - HashInterface service = reference.get(); // 注æ„:æ¤ä»£ç†å¯¹è±¡å†…部å°è£…了所有通讯细节,对象较é‡ï¼Œè¯·ç¼“å˜å¤ç”¨ + List<URL> urls = reference.toUrls(); + // æ·»åŠ ç›´è¿žçš„ provider åœ°å€ + urls.add(new URL(Constants.DUBBO_PROTOCOL, "localhost", 20880, reference.getInterface())); + urls.add(new URL(Constants.DUBBO_PROTOCOL, "localhost", 20880, reference.getInterface())); + + HashInterface service = reference.get(); while (true) { Thread.sleep(1000); System.out.println(service.hash("hahaha")); diff --git a/pom.xml b/pom.xml index f3753cf..5a58537 100644 --- a/pom.xml +++ b/pom.xml @@ -59,7 +59,6 @@ <version>${project.version}</version> </dependency> <!--internal end--> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> @@ -70,6 +69,11 @@ <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.9</version> + </dependency> </dependencies> </dependencyManagement> <build> -- GitLab