This is an automated email from the ASF dual-hosted git repository.
liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac8659040 modify dubbo plugin configuration based on selector (#5953)
9ac8659040 is described below
commit 9ac8659040e83a4b7c85d3c3aab632b3a380e275
Author: Wweiei <[email protected]>
AuthorDate: Sat Jun 21 00:48:42 2025 +0800
modify dubbo plugin configuration based on selector (#5953)
* modify dubbo plugin configuration based on selector
* code optimizationďźchange some magic value in ApacheDubboConfigCache
* fix: dubbo plugin configuration base on selector code review
---------
Co-authored-by: xiaoyu <[email protected]>
Co-authored-by: aias00 <[email protected]>
Co-authored-by: zhengpeng <[email protected]>
Co-authored-by: VampireAchao <[email protected]>
---
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 | 4 +-
db/upgrade/2.7.0-upgrade-2.7.1-ob.sql | 4 +-
db/upgrade/2.7.0-upgrade-2.7.1-og.sql | 4 +-
db/upgrade/2.7.0-upgrade-2.7.1-oracle.sql | 3 +
db/upgrade/2.7.0-upgrade-2.7.1-pg.sql | 2 +
.../apache/shenyu/common/constant/Constants.java | 15 ++
.../src/main/resources/application.yml | 2 +-
.../plugin/apache/dubbo/ApacheDubboPlugin.java | 2 +-
.../apache/dubbo/cache/ApacheDubboConfigCache.java | 287 +++++++++++++++++++--
.../dubbo/handler/ApacheDubboMetaDataHandler.java | 8 +-
.../handler/ApacheDubboPluginDataHandler.java | 12 +
.../dubbo/proxy/ApacheDubboProxyService.java | 111 ++++++--
.../dubbo/proxy/ApacheDubboProxyServiceTest.java | 15 +-
.../handler/AbstractDubboMetaDataHandler.java | 4 +-
.../handler/AbstractDubboPluginDataHandler.java | 12 +
.../AbstractDubboPluginDataHandlerTest.java | 8 +
21 files changed, 464 insertions(+), 46 deletions(-)
diff --git a/db/init/mysql/schema.sql b/db/init/mysql/schema.sql
index d46058a5e2..61f50e9a74 100644
--- a/db/init/mysql/schema.sql
+++ b/db/init/mysql/schema.sql
@@ -1092,7 +1092,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');
@@ -1102,6 +1102,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 3878810db5..5a39df2c01 100644
--- a/db/init/ob/schema.sql
+++ b/db/init/ob/schema.sql
@@ -1073,7 +1073,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');
@@ -1083,6 +1083,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 fffe27c5f1..1a6aad9979 100644
--- a/db/init/og/create-table.sql
+++ b/db/init/og/create-table.sql
@@ -1121,7 +1121,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');
@@ -1131,6 +1131,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 5b32ffc1e9..2e17aa9850 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 0e171d5020..0f113c3292 100644
--- a/db/init/pg/create-table.sql
+++ b/db/init/pg/create-table.sql
@@ -1181,7 +1181,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');
@@ -1191,6 +1191,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 8147c4d10a..d2c92c4329 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
@@ -202,4 +202,6 @@ INSERT INTO `permission` VALUES ('1697146860569742758',
'1346358560427216896', '
INSERT INTO `permission` VALUES ('1697146860569742759', '1346358560427216896',
'1844026099075564867', '2023-08-31 07:18:37', '2023-08-31 07:18:37');
INSERT INTO `permission` VALUES ('1697146860569742760', '1346358560427216896',
'1844026099075564868', '2023-08-31 07:18:37', '2023-08-31 07:18:37');
-DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
\ No newline at end of file
+DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
+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 8b89f06470..062be4dac8 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
@@ -197,4 +197,6 @@ INSERT INTO `permission` VALUES ('1697146860569742758',
'1346358560427216896', '
INSERT INTO `permission` VALUES ('1697146860569742759', '1346358560427216896',
'1844026099075564867', '2023-08-31 07:18:37', '2023-08-31 07:18:37');
INSERT INTO `permission` VALUES ('1697146860569742760', '1346358560427216896',
'1844026099075564868', '2023-08-31 07:18:37', '2023-08-31 07:18:37');
-DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
\ No newline at end of file
+DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
+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 67ef81f716..d96098371b 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
@@ -211,4 +211,6 @@ INSERT INTO "public"."permission" VALUES
('1697146860569742758', '13463585604272
INSERT INTO "public"."permission" VALUES ('1697146860569742759',
'1346358560427216896', '1844026099075564867', '2023-08-31 07:18:37',
'2023-08-31 07:18:37');
INSERT INTO "public"."permission" VALUES ('1697146860569742760',
'1346358560427216896', '1844026099075564868', '2023-08-31 07:18:37',
'2023-08-31 07:18:37');
-DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
\ No newline at end of file
+DELETE FROM `plugin_handle` WHERE `plugin_id` = '8';
+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 f8328f5d9d..d3c173bc7f 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
@@ -383,7 +383,10 @@ VALUES ('1899702472330051584', '51', 'keyName', 'keyName',
2, 2, 2, '{"required"
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 ('1899702529972371456', '51', 'tokenLimit', 'tokenLimit', 1, 2, 3,
'{"required":"0","rule":""}', sysdate, sysdate);
+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;
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(plugin(id)) */ INTO plugin (id, name,
config, role, sort, enabled) VALUES ('53', 'aiRequestTransformer', NULL, 'Ai',
65, 0);
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (namespace_plugin_rel(id)) */ INTO
namespace_plugin_rel (id,namespace_id,plugin_id, config, sort, enabled) VALUES
('1801816010882822190','649330b6-c2d7-4edc-be8e-8a54df9eb385','53', NULL, 65,
0);
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 a73fd053d0..d83087009c 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
@@ -176,6 +176,8 @@ INSERT INTO "public"."plugin_handle" VALUES
('1899702350766538752', '51', 'aiTok
INSERT INTO "public"."plugin_handle" VALUES ('1899702411294539776', '51',
'timeWindowSeconds', 'timeWindowSeconds', 1, 2, 1,
'{"required":"0","rule":""}', '2025-03-12 06:02:04.155', '2025-03-12
06:02:04.155');
INSERT INTO "public"."plugin_handle" VALUES ('1899702472330051584', '51',
'keyName', 'keyName', 2, 2, 2, '{"required":"0","rule":""}', '2025-03-12
06:02:18.707', '2025-03-12 06:02:18.707');
INSERT INTO "public"."plugin_handle" VALUES ('1899702529972371456', '51',
'tokenLimit', 'tokenLimit', 1, 2, 3, '{"required":"0","rule":""}', '2025-03-12
06:02:32.450', '2025-03-12 06:02:32.450');
+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;
INSERT INTO "public"."plugin" VALUES ('53', 'aiRequestTransformer', NULL,
'Ai', 65, 0, '2023-12-20 18:02:53', '2023-12-20 18:02:53', null);
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 1341bb4f74..5bd671d814 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-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 4a7c52e87a..6d8a40d3b1 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
@@ -24,7 +24,7 @@ spring:
dubbo:
registry:
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 eb1e00ff04..94a9fa1cb7 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 @@ public class ApacheDubboPlugin extends AbstractDubboPlugin {
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<Object> result = dubboProxyService.genericInvoker(param,
metaData, exchange);
+ final Mono<Object> 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 c65fa58968..0f8e5804ab 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.CacheLoader;
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.config.RegistryConfig;
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;
@@ -95,12 +107,14 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
*/
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);
@@ -164,6 +178,64 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
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<GenericService> 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<GenericService> 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(Constants.SEPARATOR_UNDERLINE);
+ 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 final class ApacheDubboConfigCache extends
DubboConfigCache {
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<GenericService> 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<GenericService> 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.
*
@@ -206,7 +308,7 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
reference.setConsumer(consumerConfig);
reference.setInterface(metaData.getServiceName());
// default protocol is dubbo
- reference.setProtocol("dubbo");
+ reference.setProtocol(CommonConstants.DUBBO);
reference.setCheck(false);
reference.setLoadbalance("gray");
@@ -232,7 +334,7 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
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
@@ -258,22 +360,139 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
}
}
if (StringUtils.isNotBlank(namespace)) {
- RegistryConfig registryConfig = new RegistryConfig();
- registryConfig.setRegister(false);
- if
(!this.registryConfig.getAddress().contains(Constants.NAMESPACE)) {
- registryConfig.setAddress(this.registryConfig.getAddress() +
"?" + Constants.NAMESPACE + "=" + namespace);
- reference.setRegistry(registryConfig);
- } else {
- String newAddress =
this.registryConfig.getAddress().substring(0,
this.registryConfig.getAddress().indexOf(Constants.NAMESPACE) + 1) +
Constants.NAMESPACE + "=" + namespace;
- registryConfig.setAddress(newAddress);
- reference.setRegistry(registryConfig);
- }
- } else {
- reference.setRegistry(registryConfig);
+ changeRegistryAddressNamespace(this.registryConfig, reference,
namespace);
+ }
+ return reference;
+ }
+
+ /**
+ * buildReference param with dubboUpstream.
+ *
+ * @param metaData metaData
+ * @param ruleData ruleData
+ * @param namespace namespace
+ * @param dubboUpstream dubboUpstream
+ * @return the reference config
+ */
+ private ReferenceConfig<GenericService> buildReference(final MetaData
metaData, final RuleData ruleData, final String namespace, final DubboUpstream
dubboUpstream) {
+ if (Objects.isNull(dubboUpstream)) {
+ return this.buildReference(metaData, namespace);
+ }
+
+ ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
+ reference.setGeneric("true");
+ reference.setAsync(true);
+ reference.setApplication(applicationConfig);
+
+ RegistryConfig registryConfigTemp = new RegistryConfig();
+ registryConfigTemp.setProtocol(dubboUpstream.getProtocol());
+ registryConfigTemp.setId(Constants.DUBBO_DEFAULT_APPLICATION_NAME);
+ registryConfigTemp.setRegister(false);
+ registryConfigTemp.setAddress(dubboUpstream.getRegistry());
+
Optional.ofNullable(dubboUpstream.getGroup()).ifPresent(registryConfigTemp::setGroup);
+
Optional.ofNullable(dubboUpstream.getVersion()).ifPresent(registryConfigTemp::setVersion);
+ 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(CommonConstants.DUBBO);
+ reference.setCheck(false);
+
+ Map<String, String> parameters = new HashMap<>(2);
+ parameters.put("dispatcher", "direct");
+ reference.setParameters(parameters);
+
+ this.configReferenceConfigWithMetaDataRpcExt(metaData.getRpcExt(),
reference);
+ if (StringUtils.isNotBlank(namespace)) {
+ changeRegistryAddressNamespace(registryConfigTemp, reference,
namespace);
}
return reference;
}
+ /**
+ * changeRegistryAddressNamespace common method.
+ *
+ * @param currentRegistryConfig currentRegistryConfig
+ * @param reference reference
+ * @param namespace namespace
+ */
+ private void changeRegistryAddressNamespace(final RegistryConfig
currentRegistryConfig, final ReferenceConfig<GenericService> reference, final
String namespace) {
+ RegistryConfig registryConfigNew = new RegistryConfig();
+ registryConfigNew.setRegister(false);
+ if (!currentRegistryConfig.getAddress().contains(Constants.NAMESPACE))
{
+ registryConfigNew.setAddress(currentRegistryConfig.getAddress() +
"?" + Constants.NAMESPACE + "=" + namespace);
+ } else {
+ String newAddress =
currentRegistryConfig.getAddress().substring(0,
currentRegistryConfig.getAddress().indexOf(Constants.NAMESPACE) + 1) +
Constants.NAMESPACE + "=" + namespace;
+ registryConfigNew.setAddress(newAddress);
+ }
+ reference.setRegistry(registryConfigNew);
+ }
+
+ /**
+ * 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<GenericService> 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
(Constants.DUBBO_SERIALIZATION_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<String, String> methodsParameters = new HashMap<>(1);
+ methodsParameters.put(Constants.DUBBO_LOAD_BALANCE,
dubboMethodParam.getLoadbalance());
+ methodConfig.setParameters(methodsParameters);
+ reference.getMethods().add(methodConfig);
+ }
+ }
+ }
+
/**
* Get reference config.
*
@@ -304,6 +523,42 @@ public final class ApacheDubboConfigCache extends
DubboConfigCache {
cache.invalidateAll();
}
+ /**
+ * Invalidate when dubbo selector update.
+ *
+ * @param selectorId the selectorId
+ */
+ public void invalidateWithSelectorId(final String selectorId) {
+ ConcurrentMap<String, ReferenceConfig<GenericService>> map =
cache.asMap();
+ Set<String> allKeys = map.keySet();
+ Set<String> 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<String, ReferenceConfig<GenericService>> map =
cache.asMap();
+ Set<String> allKeys = map.keySet();
+ Set<String> 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<String, ReferenceConfig<GenericService>> map =
cache.asMap();
+ Set<String> allKeys = map.keySet();
+ Set<String> 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 a3e340e2f5..3ad8178610 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 @@ public class ApacheDubboMetaDataHandler extends
AbstractDubboMetaDataHandler {
@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 5b36a8acd2..06678141d3 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 @@ public class ApacheDubboPluginDataHandler extends
AbstractDubboPluginDataHandler
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 f52ffa2cbf..8bfcaf45ad 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 @@ package org.apache.shenyu.plugin.apache.dubbo.proxy;
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.GenericException;
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 class ApacheDubboProxyService {
/**
* 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<Object> 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<GenericService> reference =
ApacheDubboConfigCache.getInstance().get(referenceKey);
- if (StringUtils.isEmpty(reference.getInterface())) {
- ApacheDubboConfigCache.getInstance().invalidate(referenceKey);
- reference =
ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace);
- }
+ public Mono<Object> genericInvoker(final String body, final MetaData
metaData, final SelectorData selectorData, final RuleData ruleData, final
ServerWebExchange exchange) throws ShenyuException {
+ ReferenceConfig<GenericService> reference =
this.getReferenceConfig(selectorData, ruleData, metaData, exchange);
GenericService genericService = reference.get();
+
Pair<String[], Object[]> pair;
if (StringUtils.isBlank(metaData.getParameterTypes()) ||
ParamCheckUtils.bodyIsEmpty(body)) {
pair = new ImmutablePair<>(new String[]{}, new Object[]{});
@@ -103,4 +108,80 @@ public class ApacheDubboProxyService {
Object resultFromFuture = RpcContext.getContext().getFuture();
return resultFromFuture instanceof CompletableFuture ?
(CompletableFuture<Object>) 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<GenericService> 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<DubboUpstream> 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 +
Constants.COLONS + referenceKey : referenceKey;
+ ReferenceConfig<GenericService> reference =
ApacheDubboConfigCache.getInstance().get(referenceKey);
+ if (StringUtils.isEmpty(reference.getInterface())) {
+ ApacheDubboConfigCache.getInstance().invalidate(referenceKey);
+ reference =
ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace);
+ }
+ return reference;
+ }
+
+ List<Upstream> upstreams = this.convertUpstreamList(dubboUpstreams);
+ String ip =
Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress();
+ Upstream upstream = LoadBalancerFactory.selector(upstreams,
LoadBalanceEnum.RANDOM.getName(), ip);
+ DubboUpstream dubboUpstream = dubboUpstreams.get(0);
+ for (DubboUpstream upstreamItem : dubboUpstreams) {
+ if (Objects.equals(upstreamItem.getRegistry(), upstream.getUrl())
+ && 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<GenericService> 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<Upstream> convertUpstreamList(final List<DubboUpstream>
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 33ca5b944e..f64c3d3408 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.commons.lang3.tuple.Pair;
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 final class ApacheDubboProxyServiceTest {
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 final class ApacheDubboProxyServiceTest {
field.setAccessible(true);
((LoadingCache<String, ReferenceConfig<GenericService>>)
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 8bba4acd57..cbb2373509 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 abstract class AbstractDubboMetaDataHandler
implements MetaDataHandler {
@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 0e97b721a1..c247f64826 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 abstract class AbstractDubboPluginDataHandler
implements PluginDataHandle
@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 abstract class AbstractDubboPluginDataHandler
implements PluginDataHandle
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 e9f04a234c..01ea18db3b 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 class AbstractDubboPluginDataHandlerTest {
@Override
protected void initConfigCache(final DubboRegisterConfig
dubboRegisterConfig) {
}
+
+ @Override
+ protected void invalidateReferenceBySelector(final SelectorData
selectorData) {
+ }
+
+ @Override
+ protected void invalidateReferenceByRule(final RuleData ruleData) {
+ }
};
}