From 238680296e03420f4b0e1d3bad651e96905c4f6b Mon Sep 17 00:00:00 2001 From: Wweiei Date: Fri, 7 Mar 2025 16:42:42 +0800 Subject: [PATCH 1/2] modify dubbo plugin configuration based on selector --- db/init/mysql/schema.sql | 3 +- db/init/ob/schema.sql | 3 +- db/init/og/create-table.sql | 3 +- db/init/oracle/schema.sql | 5 +- db/init/pg/create-table.sql | 3 +- db/upgrade/2.7.0-upgrade-2.7.1-mysql.sql | 2 + db/upgrade/2.7.0-upgrade-2.7.1-ob.sql | 2 + db/upgrade/2.7.0-upgrade-2.7.1-og.sql | 2 + db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql | 5 + db/upgrade/2.7.0-upgrade-2.7.1-pg.sql | 2 + .../src/main/resources/application.yml | 2 +- .../src/main/resources/application.yml | 7 +- .../apache/dubbo/ApacheDubboPlugin.java | 2 +- .../dubbo/cache/ApacheDubboConfigCache.java | 252 ++++++++++++++++++ .../handler/ApacheDubboMetaDataHandler.java | 8 +- .../handler/ApacheDubboPluginDataHandler.java | 12 + .../dubbo/proxy/ApacheDubboProxyService.java | 111 ++++++-- .../proxy/ApacheDubboProxyServiceTest.java | 15 +- .../handler/AbstractDubboMetaDataHandler.java | 4 +- .../AbstractDubboPluginDataHandler.java | 12 + .../AbstractDubboPluginDataHandlerTest.java | 8 + 21 files changed, 433 insertions(+), 30 deletions(-) diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql index 4059214b5d32..e2ae82e370bf 100644 --- a/db/init/mysql/schema.sql +++ b/db/init/mysql/schema.sql @@ -1060,7 +1060,7 @@ INSERT INTO `plugin_handle` VALUES ('1529402613204172811', '6', 'protocol', 'pro INSERT INTO `plugin_handle` VALUES ('1529402613204172812', '6', 'status', 'status', 3, 1, 8, '{\"defaultValue\":\"true\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172813', '6', 'timestamp', 'startupTime', 1, 1, 7, '{\"defaultValue\":\"0\",\"placeholder\":\"startup timestamp\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172814', '6', 'upstreamHost', 'host', 2, 1, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); -INSERT INTO `plugin_handle` VALUES ('1529402613204172815', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{\"required\":\"1\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); +INSERT INTO `plugin_handle` VALUES ('1529402613204172815', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{\"required\":\"0\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172816', '6', 'version', 'version', 2, 1, 4, '{\"required\":\"0\",\"placeholder\":\"version\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172817', '6', 'warmup', 'warmupTime', 1, 1, 6, '{\"defaultValue\":\"0\",\"placeholder\":\"warmup time ms)\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172818', '6', 'weight', 'weight', 1, 1, 5, '{\"defaultValue\":\"50\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); @@ -1070,6 +1070,7 @@ INSERT INTO `plugin_handle` VALUES ('1529402613204172821', '6', 'threads', 'thre INSERT INTO `plugin_handle` VALUES ('1529402613204172822', '6', 'queues', 'queues', 1, 3, 0, '{\"required\":\"0\",\"defaultValue\":\"0\",\"placeholder\":\"queues\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204173923', '6', 'retries', 'retries', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204173924', '6', 'timeout', 'timeout', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); +INSERT INTO `plugin_handle` VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{\"required\":\"0\",\"rule\":\"\"}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1529402613204172823', '26', 'host', 'host', 2, 1, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172824', '26', 'protocol', 'protocol', 2, 1, 2, '{\"required\":\"0\",\"defaultValue\":\"\",\"placeholder\":\"ws://\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172825', '26', 'url', 'ip:port', 2, 1, 1, '{\"required\":\"1\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); diff --git a/db/init/ob/schema.sql b/db/init/ob/schema.sql index 6842d16f417c..1c36683918be 100644 --- a/db/init/ob/schema.sql +++ b/db/init/ob/schema.sql @@ -1053,7 +1053,7 @@ INSERT INTO `plugin_handle` VALUES ('1529402613204172811', '6', 'protocol', 'pro INSERT INTO `plugin_handle` VALUES ('1529402613204172812', '6', 'status', 'status', 3, 1, 8, '{\"defaultValue\":\"true\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172813', '6', 'timestamp', 'startupTime', 1, 1, 7, '{\"defaultValue\":\"0\",\"placeholder\":\"startup timestamp\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172814', '6', 'upstreamHost', 'host', 2, 1, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); -INSERT INTO `plugin_handle` VALUES ('1529402613204172815', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{\"required\":\"1\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); +INSERT INTO `plugin_handle` VALUES ('1529402613204172815', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{\"required\":\"0\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172816', '6', 'version', 'version', 2, 1, 4, '{\"required\":\"0\",\"placeholder\":\"version\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172817', '6', 'warmup', 'warmupTime', 1, 1, 6, '{\"defaultValue\":\"0\",\"placeholder\":\"warmup time ms)\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172818', '6', 'weight', 'weight', 1, 1, 5, '{\"defaultValue\":\"50\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); @@ -1063,6 +1063,7 @@ INSERT INTO `plugin_handle` VALUES ('1529402613204172821', '6', 'threads', 'thre INSERT INTO `plugin_handle` VALUES ('1529402613204172822', '6', 'queues', 'queues', 1, 3, 0, '{\"required\":\"0\",\"defaultValue\":\"0\",\"placeholder\":\"queues\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204173923', '6', 'retries', 'retries', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204173924', '6', 'timeout', 'timeout', 3, 2, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); +INSERT INTO `plugin_handle` VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{\"required\":\"0\",\"rule\":\"\"}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1529402613204172823', '26', 'host', 'host', 2, 1, 0, NULL, '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172824', '26', 'protocol', 'protocol', 2, 1, 2, '{\"required\":\"0\",\"defaultValue\":\"\",\"placeholder\":\"ws://\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); INSERT INTO `plugin_handle` VALUES ('1529402613204172825', '26', 'url', 'ip:port', 2, 1, 1, '{\"required\":\"1\",\"placeholder\":\"\",\"rule\":\"\"}', '2022-05-25 18:02:53', '2022-05-25 18:02:53'); diff --git a/db/init/og/create-table.sql b/db/init/og/create-table.sql index 40e476d58d17..bdca18391ba0 100644 --- a/db/init/og/create-table.sql +++ b/db/init/og/create-table.sql @@ -1123,7 +1123,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330604', '6', 'protoc INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330605', '6', 'status', 'status', 3, 1, 8, '{"defaultValue":"true","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330606', '6', 'timestamp', 'startupTime', 1, 1, 7, '{"defaultValue":"0","placeholder":"startup timestamp","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330607', '6', 'upstreamHost', 'host', 2, 1, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); -INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330608', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"1","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); +INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330608', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"0","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330609', '6', 'version', 'version', 2, 1, 4, '{"required":"0","placeholder":"version","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330610', '6', 'warmup', 'warmupTime', 1, 1, 6, '{"defaultValue":"0","placeholder":"warmup time ms)","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330611', '6', 'weight', 'weight', 1, 1, 5, '{"defaultValue":"50","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); @@ -1133,6 +1133,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524866', '6', 'thread INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524867', '6', 'queues', 'queues', 1, 3, 0, '{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173923', '6', 'timeout', 'timeout', 3, 2, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173924', '6', 'retries', 'retries', 3, 2, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); +INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","rule":""}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524868', '26', 'host', 'host', 2, 1, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524869', '26', 'protocol', 'protocol', 2, 1, 2, '{"required":"0","defaultValue":"","placeholder":"ws://","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524870', '26', 'url', 'ip:port', 2, 1, 1, '{"required":"1","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); diff --git a/db/init/oracle/schema.sql b/db/init/oracle/schema.sql index 3e298b6777f0..60a05580ee17 100644 --- a/db/init/oracle/schema.sql +++ b/db/init/oracle/schema.sql @@ -1189,7 +1189,7 @@ insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ values ('1518229897214468122', '6', 'upstreamHost', 'host', 2, 1, 0, null); insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) -values ('1518229897214468123', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"1","placeholder":"","rule":""}'); +values ('1518229897214468123', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"0","placeholder":"","rule":""}'); insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) values ('1518229897214468124', '6', 'version', 'version', 2, 1, 4, '{"required":"0","placeholder":"version","rule":""}'); @@ -1221,6 +1221,9 @@ values ('1529402613204173924', '6', 'retries', 'retries', 3, 2, 0, null); insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) values ('1529402613204173925', '6', 'loadBalance', 'loadStrategy', 3, 2, 0, null); +insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) +values ('1529402613204173926', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","placeholder":"","rule":""}'); + insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) values ('1518229897214468131', '26', 'host', 'host', 2, 1, 0, null); diff --git a/db/init/pg/create-table.sql b/db/init/pg/create-table.sql index 189516001217..95bb812376de 100644 --- a/db/init/pg/create-table.sql +++ b/db/init/pg/create-table.sql @@ -1183,7 +1183,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330604', '6', 'protoc INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330605', '6', 'status', 'status', 3, 1, 8, '{"defaultValue":"true","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330606', '6', 'timestamp', 'startupTime', 1, 1, 7, '{"defaultValue":"0","placeholder":"startup timestamp","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330607', '6', 'upstreamHost', 'host', 2, 1, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); -INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330608', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"1","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); +INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330608', '6', 'upstreamUrl', 'ip:port', 2, 1, 1, '{"required":"0","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330609', '6', 'version', 'version', 2, 1, 4, '{"required":"0","placeholder":"version","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330610', '6', 'warmup', 'warmupTime', 1, 1, 6, '{"defaultValue":"0","placeholder":"warmup time ms)","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902779330611', '6', 'weight', 'weight', 1, 1, 5, '{"defaultValue":"50","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); @@ -1193,6 +1193,7 @@ INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524866', '6', 'thread INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524867', '6', 'queues', 'queues', 1, 3, 0, '{"required":"0","defaultValue":"0","placeholder":"queues","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173923', '6', 'retries', 'retries', 3, 2, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173924', '6', 'timeout', 'timeout', 3, 2, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); +INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","rule":""}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524868', '26', 'host', 'host', 2, 1, 0, NULL, '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524869', '26', 'protocol', 'protocol', 2, 1, 2, '{"required":"0","defaultValue":"","placeholder":"ws://","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); INSERT INTO "public"."plugin_handle" VALUES ('1529403902783524870', '26', 'url', 'ip:port', 2, 1, 1, '{"required":"1","placeholder":"","rule":""}', '2022-05-25 18:08:01', '2022-05-25 18:08:01'); diff --git a/db/upgrade/2.7.0-upgrade-2.7.1-mysql.sql b/db/upgrade/2.7.0-upgrade-2.7.1-mysql.sql index bef1339ff599..d5771331aad6 100755 --- a/db/upgrade/2.7.0-upgrade-2.7.1-mysql.sql +++ b/db/upgrade/2.7.0-upgrade-2.7.1-mysql.sql @@ -66,3 +66,5 @@ INSERT INTO `plugin_handle` VALUES ('1722804548510507045', '50', 'temperature', INSERT INTO `plugin_handle` VALUES ('1722804548510507046', '50', 'maxTokens', 'maxTokens', 2, 1, 5, '{\"required\":\"0\",\"rule\":\"\", \"placeholder\":\"optional,0,0.01~1\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1722804548510507047', '50', 'stream', 'stream', 3, 1, 6, '{\"defaultValue\":\"false\",\"rule\":\"\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1722804548510507048', '50', 'prompt', 'prompt', 2, 1, 7, '{\"required\":\"0\",\"rule\":\"\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); +INSERT INTO `plugin_handle` VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{\"required\":\"0\",\"rule\":\"\"}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); +UPDATE `plugin_handle` SET ext_obj = '{\"required\":\"0\",\"rule\":\"\"}' WHERE plugin_id = '6' AND label = 'ip:port' AND data_type = 2; \ No newline at end of file diff --git a/db/upgrade/2.7.0-upgrade-2.7.1-ob.sql b/db/upgrade/2.7.0-upgrade-2.7.1-ob.sql index e0fec551fdb4..7b323794c603 100755 --- a/db/upgrade/2.7.0-upgrade-2.7.1-ob.sql +++ b/db/upgrade/2.7.0-upgrade-2.7.1-ob.sql @@ -66,3 +66,5 @@ INSERT INTO `plugin_handle` VALUES ('1722804548510507045', '50', 'temperature', INSERT INTO `plugin_handle` VALUES ('1722804548510507046', '50', 'maxTokens', 'maxTokens', 2, 1, 5, '{\"required\":\"0\",\"rule\":\"\", \"placeholder\":\"optional,0,0.01~1\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1722804548510507047', '50', 'stream', 'stream', 3, 1, 6, '{\"defaultValue\":\"false\",\"rule\":\"\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO `plugin_handle` VALUES ('1722804548510507048', '50', 'prompt', 'prompt', 2, 1, 7, '{\"required\":\"0\",\"rule\":\"\"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); +INSERT INTO `plugin_handle` VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{\"required\":\"0\",\"rule\":\"\"}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); +UPDATE `plugin_handle` SET ext_obj = '{\"required\":\"0\",\"rule\":\"\"}' WHERE plugin_id = '6' AND label = 'ip:port' AND data_type = 2; \ No newline at end of file diff --git a/db/upgrade/2.7.0-upgrade-2.7.1-og.sql b/db/upgrade/2.7.0-upgrade-2.7.1-og.sql index 35334e9cf4cd..741ed25c8e98 100644 --- a/db/upgrade/2.7.0-upgrade-2.7.1-og.sql +++ b/db/upgrade/2.7.0-upgrade-2.7.1-og.sql @@ -67,3 +67,5 @@ INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507045', '50', 'tempe INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507046', '50', 'maxTokens', 'maxTokens', 2, 1, 5, '{"required":"0","rule":"", "placeholder":"optional,0,0.01~1"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507047', '50', 'stream', 'stream', 3, 1, 6, '{"defaultValue":"false","rule":""}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507048', '50', 'prompt', 'prompt', 2, 1, 7, '{"required":"0","rule":""}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); +INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","rule":""}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); +UPDATE "public"."plugin_handle" SET ext_obj = '{"required":"0","rule":""}' WHERE plugin_id = '6' AND label = 'ip:port' AND data_type = 2; \ No newline at end of file diff --git a/db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql b/db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql index deaab20389e9..067eec99187d 100755 --- a/db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql +++ b/db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql @@ -144,3 +144,8 @@ VALUES ('1722804548510507047', '50', 'stream', 'stream', 3, 1, 6, '{"defaultValu INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(id)) */ INTO plugin_handle (id, plugin_id, field, label, data_type, type, sort, ext_obj, date_created, date_updated) VALUES ('1722804548510507048', '50', 'prompt', 'prompt', 2, 1, 7, '{"required":"0","rule":""}', to_timestamp('2024-01-02 17:20:50.233', 'YYYY-MM-DD HH24:MI:SS.FF3'), to_timestamp('2024-01-02 17:20:50.233', 'YYYY-MM-DD HH24:MI:SS.FF3')); + +insert /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin_handle(plugin_id, field, type)) */ into plugin_handle (ID, PLUGIN_ID, FIELD, LABEL, DATA_TYPE, TYPE, SORT, EXT_OBJ) +values ('1529402613204173926', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","placeholder":"","rule":""}'); + +UPDATE plugin_handle SET ext_obj = '{"required":"0","rule":""}' WHERE plugin_id = '6' AND label = 'ip:port' AND data_type = 2; \ No newline at end of file diff --git a/db/upgrade/2.7.0-upgrade-2.7.1-pg.sql b/db/upgrade/2.7.0-upgrade-2.7.1-pg.sql index c333b38cd189..46e3a2065bd6 100755 --- a/db/upgrade/2.7.0-upgrade-2.7.1-pg.sql +++ b/db/upgrade/2.7.0-upgrade-2.7.1-pg.sql @@ -66,3 +66,5 @@ INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507045', '50', 'tempe INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507046', '50', 'maxTokens', 'maxTokens', 2, 1, 5, '{"required":"0","rule":"", "placeholder":"optional,0,0.01~1"}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507047', '50', 'stream', 'stream', 3, 1, 6, '{"defaultValue":"false","rule":""}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); INSERT INTO "public"."plugin_handle" VALUES ('1722804548510507048', '50', 'prompt', 'prompt', 2, 1, 7, '{"required":"0","rule":""}', '2024-01-02 17:20:50.233', '2024-01-02 17:20:50.233'); +INSERT INTO "public"."plugin_handle" VALUES ('1529402613204173925', '6', 'registry', 'registry', 2, 1, 0, '{"required":"0","rule":""}', '2025-02-27 17:20:50.233', '2025-02-27 17:20:50.233'); +UPDATE "public"."plugin_handle" SET ext_obj = '{"required":"0","rule":""}' WHERE plugin_id = '6' AND label = 'ip:port' AND data_type = 2; \ No newline at end of file diff --git a/shenyu-admin/src/main/resources/application.yml b/shenyu-admin/src/main/resources/application.yml index 7a42448b22e0..f066cc6068d6 100755 --- a/shenyu-admin/src/main/resources/application.yml +++ b/shenyu-admin/src/main/resources/application.yml @@ -21,7 +21,7 @@ spring: application: name: shenyu-admin profiles: - active: h2 + active: mysql thymeleaf: cache: true encoding: utf-8 diff --git a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml index 4a7c52e87a17..1ab4ba492bed 100644 --- a/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml +++ b/shenyu-examples/shenyu-examples-dubbo/shenyu-examples-apache-dubbo-service/src/main/resources/application.yml @@ -14,7 +14,7 @@ # limitations under the License. server: - port: 8011 + port: 8012 address: 0.0.0.0 servlet: context-path: / @@ -23,8 +23,9 @@ spring: allow-bean-definition-overriding: true dubbo: registry: - address: zookeeper://localhost:2181 - + address: nacos://127.0.0.1:8849?namespace=namespace1 +# address: zookeeper://localhost:2181 + shenyu: namespace: 649330b6-c2d7-4edc-be8e-8a54df9eb385 register: diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java index eb1e00ff04d9..94a9fa1cb7f4 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java @@ -73,7 +73,7 @@ protected Mono doDubboInvoker(final ServerWebExchange exchange, RpcContext.getClientAttachment().setAttachment(Constants.DUBBO_SELECTOR_ID, selector.getId()); RpcContext.getClientAttachment().setAttachment(Constants.DUBBO_RULE_ID, rule.getId()); RpcContext.getClientAttachment().setAttachment(Constants.DUBBO_REMOTE_ADDRESS, Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress()); - final Mono result = dubboProxyService.genericInvoker(param, metaData, exchange); + final Mono result = dubboProxyService.genericInvoker(param, metaData, selector, rule, exchange); return result.then(chain.execute(exchange)); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java index c65fa589682c..b0505a8b91a9 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java @@ -22,14 +22,21 @@ import com.google.common.cache.LoadingCache; import com.google.common.cache.RemovalListener; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; +import java.util.StringJoiner; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + import jakarta.annotation.Nonnull; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.dubbo.common.constants.CommonConstants; import org.apache.dubbo.config.ApplicationConfig; @@ -40,11 +47,16 @@ import org.apache.dubbo.rpc.service.GenericService; import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.dto.MetaData; +import org.apache.shenyu.common.dto.RuleData; import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig; +import org.apache.shenyu.common.dto.convert.rule.impl.DubboRuleHandle; +import org.apache.shenyu.common.dto.convert.selector.DubboUpstream; import org.apache.shenyu.common.exception.ShenyuException; +import org.apache.shenyu.common.utils.DigestUtils; import org.apache.shenyu.plugin.dubbo.common.cache.DubboConfigCache; import org.apache.shenyu.plugin.dubbo.common.cache.DubboMethodParam; import org.apache.shenyu.plugin.dubbo.common.cache.DubboParam; +import org.apache.shenyu.plugin.dubbo.common.handler.AbstractDubboPluginDataHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,6 +108,8 @@ public static ApacheDubboConfigCache getInstance() { public void init(final DubboRegisterConfig dubboRegisterConfig) { if (Objects.isNull(applicationConfig)) { applicationConfig = new ApplicationConfig("shenyu_proxy"); + applicationConfig.setQosEnable(false); + applicationConfig.setRegisterConsumer(true); } if (needUpdateRegistryConfig(dubboRegisterConfig)) { RegistryConfig registryConfigTemp = new RegistryConfig(); @@ -164,6 +178,64 @@ public ReferenceConfig initRefN(final MetaData metaData, final S return build(metaData, namespace); } + /** + * Init ref reference config use dubboUpstream. + * + * @param selectorId the selectorId + * @param ruleData the rule data + * @param metaData the meta data + * @param namespace namespace + * @param dubboUpstream dubboUpstream + * @return the reference config + */ + public ReferenceConfig initRefN(final String selectorId, final RuleData ruleData, final MetaData metaData, final String namespace, final DubboUpstream dubboUpstream) { + try { + String cacheKey = generateUpstreamCacheKey(selectorId, ruleData.getId(), metaData.getId(), namespace, dubboUpstream); + ReferenceConfig referenceConfig = cache.get(cacheKey); + if (StringUtils.isNoneBlank(referenceConfig.getInterface())) { + return referenceConfig; + } + } catch (ExecutionException e) { + LOG.error("initRefN dubbo ref exception", e); + } + return build(metaData, ruleData, namespace, selectorId, dubboUpstream); + } + + /** + * generate dubbo upstream reference cache key. + * + * @param selectorId selectorId + * @param ruleId ruleId + * @param metaDataId metaDataId + * @param namespace namespace + * @param dubboUpstream dubboUpstream + * @return the reference config cache key + */ + public String generateUpstreamCacheKey(final String selectorId, final String ruleId, final String metaDataId, final String namespace, final DubboUpstream dubboUpstream) { + StringJoiner stringJoiner = new StringJoiner("_"); + if (StringUtils.isNotBlank(namespace)) { + stringJoiner.add(namespace); + } + stringJoiner.add(selectorId); + stringJoiner.add(ruleId); + stringJoiner.add(metaDataId); + if (StringUtils.isNotBlank(dubboUpstream.getProtocol())) { + stringJoiner.add(dubboUpstream.getProtocol()); + } + + // use registry hash to short reference cache key + String registryHash = DigestUtils.md5Hex(dubboUpstream.getRegistry()); + stringJoiner.add(registryHash); + + if (StringUtils.isNotBlank(dubboUpstream.getVersion())) { + stringJoiner.add(dubboUpstream.getVersion()); + } + if (StringUtils.isNotBlank(dubboUpstream.getGroup())) { + stringJoiner.add(dubboUpstream.getGroup()); + } + return stringJoiner.toString(); + } + /** * build with dynamic namespace. * @@ -189,6 +261,36 @@ public ReferenceConfig build(final MetaData metaData, final Stri return reference; } + /** + * build with dynamic namespace and selectorData's dubboUpstream、ruleData's custom param. + * + * @param metaData metaData + * @param ruleData ruleData + * @param namespace namespace + * @param selectorId selectorId + * @param dubboUpstream dubboUpstream + * @return the reference config + */ + @SuppressWarnings("deprecation") + public ReferenceConfig build(final MetaData metaData, final RuleData ruleData, final String namespace, final String selectorId, final DubboUpstream dubboUpstream) { + if (Objects.isNull(dubboUpstream)) { + return this.build(metaData, namespace); + } + + ReferenceConfig reference = buildReference(metaData, ruleData, namespace, dubboUpstream); + try { + Object obj = reference.get(); + if (Objects.nonNull(obj)) { + LOG.info("buildN init apache dubbo reference success there meteData is :{}", metaData); + String cacheKey = this.generateUpstreamCacheKey(selectorId, ruleData.getId(), metaData.getId(), namespace, dubboUpstream); + cache.put(cacheKey, reference); + } + } catch (Exception e) { + LOG.error("buildN init apache dubbo reference exception", e); + } + return reference; + } + /** * buildReference param. * @@ -274,6 +376,120 @@ private ReferenceConfig buildReference(final MetaData metaData, return reference; } + /** + * buildReference param with dubboUpstream. + * + * @param metaData metaData + * @param ruleData ruleData + * @param namespace namespace + * @param dubboUpstream dubboUpstream + * @return the reference config + */ + private ReferenceConfig buildReference(final MetaData metaData, final RuleData ruleData, final String namespace, final DubboUpstream dubboUpstream) { + if (Objects.isNull(dubboUpstream)) { + return this.buildReference(metaData, namespace); + } + + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setGeneric("true"); + reference.setAsync(true); + reference.setApplication(applicationConfig); + + RegistryConfig registryConfigTemp = new RegistryConfig(); + registryConfigTemp.setProtocol(dubboUpstream.getProtocol()); + registryConfigTemp.setId("shenyu_proxy"); + registryConfigTemp.setRegister(false); + registryConfigTemp.setAddress(dubboUpstream.getRegistry()); + Optional.ofNullable(dubboUpstream.getGroup()).ifPresent(registryConfigTemp::setGroup); + Optional.ofNullable(dubboUpstream.getVersion()).ifPresent(registryConfigTemp::setVersion); + if (StringUtils.isNotBlank(namespace)) { + if (!registryConfigTemp.getAddress().contains(Constants.NAMESPACE)) { + registryConfigTemp.setAddress(registryConfigTemp.getAddress() + "?" + Constants.NAMESPACE + "=" + namespace); + } else { + String newAddress = registryConfigTemp.getAddress().substring(0, registryConfigTemp.getAddress().indexOf(Constants.NAMESPACE) + 1) + Constants.NAMESPACE + "=" + namespace; + registryConfigTemp.setAddress(newAddress); + } + } + reference.setRegistry(registryConfigTemp); + + DubboRuleHandle dubboRuleHandle = AbstractDubboPluginDataHandler.RULE_CACHED_HANDLE.get().obtainHandle(ruleData.getId()); + ConsumerConfig consumerConfigTmp = new ConsumerConfig(); + if (ObjectUtils.isNotEmpty(dubboRuleHandle)) { + consumerConfigTmp.refresh(); + Optional.ofNullable(consumerConfig.getThreadpool()).ifPresent(consumerConfigTmp::setThreadpool); + Optional.ofNullable(consumerConfig.getCorethreads()).ifPresent(consumerConfigTmp::setCorethreads); + Optional.ofNullable(consumerConfig.getThreads()).ifPresent(consumerConfigTmp::setThreads); + Optional.ofNullable(consumerConfig.getQueues()).ifPresent(consumerConfigTmp::setQueues); + consumerConfigTmp.setRetries(dubboRuleHandle.getRetries()); + consumerConfigTmp.setTimeout((int) dubboRuleHandle.getTimeout()); + } + + reference.setConsumer(consumerConfigTmp); + reference.setInterface(metaData.getServiceName()); + // default protocol is dubbo + reference.setProtocol("dubbo"); + reference.setCheck(false); + + Map parameters = new HashMap<>(2); + parameters.put("dispatcher", "direct"); + reference.setParameters(parameters); + + this.configReferenceConfigWithMetaDataRpcExt(metaData.getRpcExt(), reference); + return reference; + } + + /** + * Config ReferenceConfig dubbo param with metaData rpc ext. + * + * @param rpcExt the rpc ext + * @param reference the reference + */ + private void configReferenceConfigWithMetaDataRpcExt(final String rpcExt, final ReferenceConfig reference) { + DubboParam dubboParam = parserToDubboParam(rpcExt); + if (Objects.isNull(dubboParam)) { + return; + } + + if (StringUtils.isNoneBlank(dubboParam.getVersion())) { + reference.setVersion(dubboParam.getVersion()); + } + if (StringUtils.isNoneBlank(dubboParam.getGroup())) { + reference.setGroup(dubboParam.getGroup()); + } + if (StringUtils.isNoneBlank(dubboParam.getUrl())) { + reference.setUrl(dubboParam.getUrl()); + } + if (StringUtils.isNoneBlank(dubboParam.getCluster())) { + reference.setCluster(dubboParam.getCluster()); + } + if (StringUtils.isNoneBlank(dubboParam.getLoadbalance())) { + reference.getParameters().put(Constants.DUBBO_LOAD_BALANCE, dubboParam.getLoadbalance()); + } + if ("protobuf".equals(dubboParam.getSerialization())) { + reference.setGeneric(CommonConstants.GENERIC_SERIALIZATION_PROTOBUF); + } + // set dubbo sub protocol + Optional.ofNullable(dubboParam.getProtocol()).ifPresent(reference::setProtocol); + Optional.ofNullable(dubboParam.getTimeout()).ifPresent(reference::setTimeout); + Optional.ofNullable(dubboParam.getRetries()).ifPresent(reference::setRetries); + Optional.ofNullable(dubboParam.getSent()).ifPresent(reference::setSent); + // methods + if (CollectionUtils.isNotEmpty(dubboParam.getMethods())) { + reference.setMethods(new ArrayList<>()); + for (DubboMethodParam dubboMethodParam : dubboParam.getMethods()) { + MethodConfig methodConfig = new MethodConfig(); + methodConfig.setName(dubboMethodParam.getName()); + methodConfig.setRetries(dubboMethodParam.getRetries()); + methodConfig.setTimeout(dubboMethodParam.getTimeout()); + methodConfig.setSent(dubboMethodParam.getSent()); + Map methodsParameters = new HashMap<>(1); + methodsParameters.put(Constants.DUBBO_LOAD_BALANCE, dubboMethodParam.getLoadbalance()); + methodConfig.setParameters(methodsParameters); + reference.getMethods().add(methodConfig); + } + } + } + /** * Get reference config. * @@ -304,6 +520,42 @@ public void invalidateAll() { cache.invalidateAll(); } + /** + * Invalidate when dubbo selector update. + * + * @param selectorId the selectorId + */ + public void invalidateWithSelectorId(final String selectorId) { + ConcurrentMap> map = cache.asMap(); + Set allKeys = map.keySet(); + Set needInvalidateKeys = allKeys.stream().filter(key -> key.contains(selectorId)).collect(Collectors.toSet()); + needInvalidateKeys.forEach(cache::invalidate); + } + + /** + * Invalidate when dubbo rule update. + * + * @param ruleId the ruleId + */ + public void invalidateWithRuleId(final String ruleId) { + ConcurrentMap> map = cache.asMap(); + Set allKeys = map.keySet(); + Set needInvalidateKeys = allKeys.stream().filter(key -> key.contains(ruleId)).collect(Collectors.toSet()); + needInvalidateKeys.forEach(cache::invalidate); + } + + /** + * Invalidate when dubbo metadata update. + * + * @param metadataId the metadataId + */ + public void invalidateWithMetadataId(final String metadataId) { + ConcurrentMap> map = cache.asMap(); + Set allKeys = map.keySet(); + Set needInvalidateKeys = allKeys.stream().filter(key -> key.contains(metadataId)).collect(Collectors.toSet()); + needInvalidateKeys.forEach(cache::invalidate); + } + /** * The type Application config cache instance. */ diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboMetaDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboMetaDataHandler.java index a3e340e2f59a..3ad8178610fd 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboMetaDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboMetaDataHandler.java @@ -41,10 +41,14 @@ protected void initReference(final MetaData metaData) { @Override protected void updateReference(final MetaData metaData) { ApacheDubboConfigCache.getInstance().build(metaData, ""); + // remove old upstream reference + ApacheDubboConfigCache.getInstance().invalidateWithMetadataId(metaData.getId()); } @Override - protected void invalidateReference(final String path) { - ApacheDubboConfigCache.getInstance().invalidate(path); + protected void invalidateReference(final MetaData metaData) { + ApacheDubboConfigCache.getInstance().invalidate(metaData.getPath()); + // remove old upstream reference + ApacheDubboConfigCache.getInstance().invalidateWithMetadataId(metaData.getId()); } } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java index 5b36a8acd21b..06678141d3ed 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java @@ -17,6 +17,8 @@ package org.apache.shenyu.plugin.apache.dubbo.handler; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig; import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache; import org.apache.shenyu.plugin.dubbo.common.handler.AbstractDubboPluginDataHandler; @@ -31,4 +33,14 @@ protected void initConfigCache(final DubboRegisterConfig dubboRegisterConfig) { ApacheDubboConfigCache.getInstance().init(dubboRegisterConfig); ApacheDubboConfigCache.getInstance().invalidateAll(); } + + @Override + protected void invalidateReferenceBySelector(final SelectorData selectorData) { + ApacheDubboConfigCache.getInstance().invalidateWithSelectorId(selectorData.getId()); + } + + @Override + protected void invalidateReferenceByRule(final RuleData ruleData) { + ApacheDubboConfigCache.getInstance().invalidateWithRuleId(ruleData.getId()); + } } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java index f52ffa2cbfa0..736aa6f1973e 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java @@ -19,6 +19,10 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.List; +import java.util.Collections; +import java.util.Optional; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -30,12 +34,20 @@ import org.apache.dubbo.rpc.service.GenericService; import org.apache.shenyu.common.constant.Constants; import org.apache.shenyu.common.dto.MetaData; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; +import org.apache.shenyu.common.dto.convert.selector.DubboUpstream; +import org.apache.shenyu.common.enums.LoadBalanceEnum; import org.apache.shenyu.common.enums.ResultEnum; import org.apache.shenyu.common.exception.ShenyuException; +import org.apache.shenyu.common.utils.GsonUtils; import org.apache.shenyu.common.utils.JsonUtils; import org.apache.shenyu.common.utils.ParamCheckUtils; +import org.apache.shenyu.loadbalancer.entity.Upstream; +import org.apache.shenyu.loadbalancer.factory.LoadBalancerFactory; import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache; import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService; +import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; @@ -58,25 +70,18 @@ public ApacheDubboProxyService(final DubboParamResolveService dubboParamResolveS /** * Generic invoker object. * - * @param body the body - * @param metaData the meta data - * @param exchange the exchange + * @param body the body + * @param metaData the meta data + * @param selectorData the selector data + * @param ruleData the rule data + * @param exchange the webExchange * @return the object * @throws ShenyuException the shenyu exception */ - public Mono genericInvoker(final String body, final MetaData metaData, final ServerWebExchange exchange) throws ShenyuException { - String referenceKey = metaData.getPath(); - String namespace = ""; - if (CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.NAMESPACE))) { - namespace = exchange.getRequest().getHeaders().get(Constants.NAMESPACE).get(0); - referenceKey = namespace + ":" + referenceKey; - } - ReferenceConfig reference = ApacheDubboConfigCache.getInstance().get(referenceKey); - if (StringUtils.isEmpty(reference.getInterface())) { - ApacheDubboConfigCache.getInstance().invalidate(referenceKey); - reference = ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace); - } + public Mono genericInvoker(final String body, final MetaData metaData, final SelectorData selectorData, final RuleData ruleData, final ServerWebExchange exchange) throws ShenyuException { + ReferenceConfig reference = this.getReferenceConfig(selectorData, ruleData, metaData, exchange); GenericService genericService = reference.get(); + Pair pair; if (StringUtils.isBlank(metaData.getParameterTypes()) || ParamCheckUtils.bodyIsEmpty(body)) { pair = new ImmutablePair<>(new String[]{}, new Object[]{}); @@ -103,4 +108,80 @@ private CompletableFuture invokeAsync(final GenericService genericServic Object resultFromFuture = RpcContext.getContext().getFuture(); return resultFromFuture instanceof CompletableFuture ? (CompletableFuture) resultFromFuture : CompletableFuture.completedFuture(resultFromFuture); } + + /** + * get dubbo reference config. + * + * @param selectorData the selector data + * @param ruleData the rule data + * @param metaData the meta data + * @param exchange the webExchange + * @return dubbo reference config + */ + private ReferenceConfig getReferenceConfig(final SelectorData selectorData, final RuleData ruleData, final MetaData metaData, final ServerWebExchange exchange) { + String referenceKey = metaData.getPath(); + String namespace = ""; + if (CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.NAMESPACE))) { + namespace = exchange.getRequest().getHeaders().get(Constants.NAMESPACE).get(0); + } + + List dubboUpstreams = GsonUtils.getInstance().fromList(selectorData.getHandle(), DubboUpstream.class); + dubboUpstreams = CollectionUtils.isEmpty(dubboUpstreams) ? null + : dubboUpstreams.stream().filter(u -> u.isStatus() && StringUtils.isNotBlank(u.getRegistry())).collect(Collectors.toList()); + // if dubboUpstreams is empty, use default plugin config + if (CollectionUtils.isEmpty(dubboUpstreams)) { + referenceKey = StringUtils.isNotBlank(namespace) ? namespace + ":" + referenceKey : referenceKey; + ReferenceConfig reference = ApacheDubboConfigCache.getInstance().get(referenceKey); + if (StringUtils.isEmpty(reference.getInterface())) { + ApacheDubboConfigCache.getInstance().invalidate(referenceKey); + reference = ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace); + } + return reference; + } + + List upstreams = this.convertUpstreamList(dubboUpstreams); + String ip = Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress(); + Upstream upstream = LoadBalancerFactory.selector(upstreams, LoadBalanceEnum.RANDOM.getName(), ip); + DubboUpstream dubboUpstream = null; + for (DubboUpstream upstreamItem : dubboUpstreams) { + if (Objects.equals(upstreamItem.getRegistry(), upstreamItem.getRegistry()) + && Objects.equals(upstreamItem.getProtocol(), upstream.getProtocol()) + && Objects.equals(upstreamItem.getVersion(), upstream.getVersion()) + && Objects.equals(upstreamItem.getGroup(), upstream.getGroup())) { + dubboUpstream = upstreamItem; + break; + } + } + + referenceKey = ApacheDubboConfigCache.getInstance().generateUpstreamCacheKey(selectorData.getId(), ruleData.getId(), metaData.getId(), namespace, dubboUpstream); + ReferenceConfig reference = ApacheDubboConfigCache.getInstance().get(referenceKey); + if (StringUtils.isEmpty(reference.getInterface())) { + ApacheDubboConfigCache.getInstance().invalidate(referenceKey); + reference = ApacheDubboConfigCache.getInstance().initRefN(selectorData.getId(), ruleData, metaData, namespace, dubboUpstream); + } + return reference; + } + + /** + * convert get DubboUpstream to Upstream. + * + * @param upstreamList the dubbo upstream list + * @return upstream list + */ + private List convertUpstreamList(final List upstreamList) { + if (ObjectUtils.isEmpty(upstreamList)) { + return Collections.emptyList(); + } + return upstreamList.stream().map(u -> { + return Upstream.builder() + .protocol(u.getProtocol()) + .url(u.getRegistry()) + .version(u.getVersion()) + .group(u.getGroup()) + .weight(u.getWeight()) + .status(u.isStatus()) + .timestamp(Optional.of(u.getTimestamp()).orElse(System.currentTimeMillis())) + .build(); + }).collect(Collectors.toList()); + } } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java index 33ca5b944ecd..f64c3d340860 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java @@ -23,6 +23,8 @@ import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.rpc.service.GenericService; import org.apache.shenyu.common.dto.MetaData; +import org.apache.shenyu.common.dto.RuleData; +import org.apache.shenyu.common.dto.SelectorData; import org.apache.shenyu.common.enums.RpcTypeEnum; import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache; import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService; @@ -60,6 +62,10 @@ public final class ApacheDubboProxyServiceTest { private MetaData metaData; + private SelectorData selectorData; + + private RuleData ruleData; + private ServerWebExchange exchange; @Mock @@ -75,6 +81,13 @@ public void setup() { metaData.setServiceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService"); metaData.setMethodName(METHOD_NAME); metaData.setRpcType(RpcTypeEnum.DUBBO.getName()); + selectorData = new SelectorData(); + selectorData.setId("1895390769043820544"); + selectorData.setPluginId("6"); + selectorData.setHandle("[]"); + ruleData = new RuleData(); + ruleData.setId("1895390769224175616"); + ruleData.setHandle("{}"); } @AfterEach @@ -95,7 +108,7 @@ public void genericInvokerTest() throws IllegalAccessException, NoSuchFieldExcep field.setAccessible(true); ((LoadingCache>) field.get(apacheDubboConfigCache)).put(PATH, referenceConfig); ApacheDubboProxyService apacheDubboProxyService = new ApacheDubboProxyService(new BodyParamResolveServiceImpl()); - apacheDubboProxyService.genericInvoker("", metaData, exchange); + apacheDubboProxyService.genericInvoker("", metaData, selectorData, ruleData, exchange); future.complete("success"); } diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboMetaDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboMetaDataHandler.java index 8bba4acd5753..cbb23735096f 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboMetaDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboMetaDataHandler.java @@ -59,11 +59,11 @@ public void handle(final MetaData metaData) { @Override public void remove(final MetaData metaData) { - invalidateReference(metaData.getPath()); + invalidateReference(metaData); META_DATA.remove(metaData.getPath()); } - protected abstract void invalidateReference(String path); + protected abstract void invalidateReference(MetaData path); @Override public String rpcType() { diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java index 0e97b721a184..c247f648265f 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java @@ -53,6 +53,10 @@ public abstract class AbstractDubboPluginDataHandler implements PluginDataHandle protected abstract void initConfigCache(DubboRegisterConfig dubboRegisterConfig); + protected abstract void invalidateReferenceBySelector(SelectorData selectorData); + + protected abstract void invalidateReferenceByRule(RuleData ruleData); + @Override public void handlerPlugin(final PluginData pluginData) { if (Objects.nonNull(pluginData) && Boolean.TRUE.equals(pluginData.getEnabled())) { @@ -71,6 +75,8 @@ public void handlerPlugin(final PluginData pluginData) { @Override public void handlerSelector(final SelectorData selectorData) { + // remove old upstream reference + this.invalidateReferenceBySelector(selectorData); if (!selectorData.getContinued()) { RULE_CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(selectorData.getId(), Constants.DEFAULT_RULE), DubboRuleHandle.newInstance()); } @@ -98,16 +104,22 @@ public void removeSelector(final SelectorData selectorData) { SELECTOR_CACHED_HANDLE.get().removeHandle(selectorData.getId()); UpstreamCacheManager.getInstance().removeByKey(selectorData.getId()); RULE_CACHED_HANDLE.get().removeHandle(CacheKeyUtils.INST.getKey(selectorData.getId(), Constants.DEFAULT_RULE)); + // remove old upstream reference + this.invalidateReferenceBySelector(selectorData); } @Override public void handlerRule(final RuleData ruleData) { RULE_CACHED_HANDLE.get().cachedHandle(ruleData.getId(), GsonUtils.getInstance().fromJson(ruleData.getHandle(), DubboRuleHandle.class)); + // remove old upstream reference + this.invalidateReferenceByRule(ruleData); } @Override public void removeRule(final RuleData ruleData) { RULE_CACHED_HANDLE.get().removeHandle(ruleData.getId()); + // remove old upstream reference + this.invalidateReferenceByRule(ruleData); } @Override diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java index e9f04a234c6d..01ea18db3ba1 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/test/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandlerTest.java @@ -49,6 +49,14 @@ public void setUp() { @Override protected void initConfigCache(final DubboRegisterConfig dubboRegisterConfig) { } + + @Override + protected void invalidateReferenceBySelector(final SelectorData selectorData) { + } + + @Override + protected void invalidateReferenceByRule(final RuleData ruleData) { + } }; } From 74a8769ddf0104a96fbfceb8ebe82fe682d9a14b Mon Sep 17 00:00:00 2001 From: Wweiei Date: Wed, 12 Mar 2025 19:27:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?code=20optimization=EF=BC=8Cchange=20some?= =?UTF-8?q?=20magic=20value=20in=20ApacheDubboConfigCache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apache/shenyu/common/constant/Constants.java | 15 +++++++++++++++ .../dubbo/cache/ApacheDubboConfigCache.java | 16 ++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java index c6713166b8e3..854d2f14abd6 100644 --- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java +++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/Constants.java @@ -26,6 +26,11 @@ public interface Constants { * The constant string separator. */ String SEPARATOR_CHARS = ";"; + + /** + * The constant string separator. + */ + String SEPARATOR_UNDERLINE = "_"; /** * The constant SUCCESS. @@ -557,6 +562,16 @@ public interface Constants { * dubbo load balance from meta data. */ String DUBBO_LOAD_BALANCE = "dubboLoadBalance"; + + /** + * dubbo serialization protobuf. + */ + String DUBBO_SERIALIZATION_PROTOBUF = "protobuf"; + + /** + * dubbo default application name. + */ + String DUBBO_DEFAULT_APPLICATION_NAME = "shenyu_proxy"; /** * dubbo group. diff --git a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java index b0505a8b91a9..b49eddc3b8f6 100644 --- a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java +++ b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java @@ -107,14 +107,14 @@ public static ApacheDubboConfigCache getInstance() { */ public void init(final DubboRegisterConfig dubboRegisterConfig) { if (Objects.isNull(applicationConfig)) { - applicationConfig = new ApplicationConfig("shenyu_proxy"); + applicationConfig = new ApplicationConfig(Constants.DUBBO_DEFAULT_APPLICATION_NAME); applicationConfig.setQosEnable(false); applicationConfig.setRegisterConsumer(true); } if (needUpdateRegistryConfig(dubboRegisterConfig)) { RegistryConfig registryConfigTemp = new RegistryConfig(); registryConfigTemp.setProtocol(dubboRegisterConfig.getProtocol()); - registryConfigTemp.setId("shenyu_proxy"); + registryConfigTemp.setId(Constants.DUBBO_DEFAULT_APPLICATION_NAME); registryConfigTemp.setRegister(false); registryConfigTemp.setAddress(dubboRegisterConfig.getRegister()); Optional.ofNullable(dubboRegisterConfig.getGroup()).ifPresent(registryConfigTemp::setGroup); @@ -212,7 +212,7 @@ public ReferenceConfig initRefN(final String selectorId, final R * @return the reference config cache key */ public String generateUpstreamCacheKey(final String selectorId, final String ruleId, final String metaDataId, final String namespace, final DubboUpstream dubboUpstream) { - StringJoiner stringJoiner = new StringJoiner("_"); + StringJoiner stringJoiner = new StringJoiner(Constants.SEPARATOR_UNDERLINE); if (StringUtils.isNotBlank(namespace)) { stringJoiner.add(namespace); } @@ -308,7 +308,7 @@ private ReferenceConfig buildReference(final MetaData metaData, reference.setConsumer(consumerConfig); reference.setInterface(metaData.getServiceName()); // default protocol is dubbo - reference.setProtocol("dubbo"); + reference.setProtocol(CommonConstants.DUBBO); reference.setCheck(false); reference.setLoadbalance("gray"); @@ -334,7 +334,7 @@ private ReferenceConfig buildReference(final MetaData metaData, if (StringUtils.isNoneBlank(dubboParam.getLoadbalance())) { reference.getParameters().put(Constants.DUBBO_LOAD_BALANCE, dubboParam.getLoadbalance()); } - if ("protobuf".equals(dubboParam.getSerialization())) { + if (Constants.DUBBO_SERIALIZATION_PROTOBUF.equals(dubboParam.getSerialization())) { reference.setGeneric(CommonConstants.GENERIC_SERIALIZATION_PROTOBUF); } // set dubbo sub protocol @@ -397,7 +397,7 @@ private ReferenceConfig buildReference(final MetaData metaData, RegistryConfig registryConfigTemp = new RegistryConfig(); registryConfigTemp.setProtocol(dubboUpstream.getProtocol()); - registryConfigTemp.setId("shenyu_proxy"); + registryConfigTemp.setId(Constants.DUBBO_DEFAULT_APPLICATION_NAME); registryConfigTemp.setRegister(false); registryConfigTemp.setAddress(dubboUpstream.getRegistry()); Optional.ofNullable(dubboUpstream.getGroup()).ifPresent(registryConfigTemp::setGroup); @@ -427,7 +427,7 @@ private ReferenceConfig buildReference(final MetaData metaData, reference.setConsumer(consumerConfigTmp); reference.setInterface(metaData.getServiceName()); // default protocol is dubbo - reference.setProtocol("dubbo"); + reference.setProtocol(CommonConstants.DUBBO); reference.setCheck(false); Map parameters = new HashMap<>(2); @@ -465,7 +465,7 @@ private void configReferenceConfigWithMetaDataRpcExt(final String rpcExt, final if (StringUtils.isNoneBlank(dubboParam.getLoadbalance())) { reference.getParameters().put(Constants.DUBBO_LOAD_BALANCE, dubboParam.getLoadbalance()); } - if ("protobuf".equals(dubboParam.getSerialization())) { + if (Constants.DUBBO_SERIALIZATION_PROTOBUF.equals(dubboParam.getSerialization())) { reference.setGeneric(CommonConstants.GENERIC_SERIALIZATION_PROTOBUF); } // set dubbo sub protocol