This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 1ca03ab5db9 Legacy issues with increasing rpccontext usage (#2987)
1ca03ab5db9 is described below

commit 1ca03ab5db9d48824802789eb74d943039f6932f
Author: 王聪洋 <[email protected]>
AuthorDate: Fri May 31 16:00:25 2024 +0800

    Legacy issues with increasing rpccontext usage (#2987)
    
    * Update attachment.md
    
    * Update context.md
---
 .../service/attachment.md                          | 35 ++++++++++++++++++++
 content/zh-cn/overview/tasks/develop/context.md    | 37 +++++++++++++++++++++-
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git 
a/content/zh-cn/overview/mannual/java-sdk/advanced-features-and-usage/service/attachment.md
 
b/content/zh-cn/overview/mannual/java-sdk/advanced-features-and-usage/service/attachment.md
index 0c36e6c006a..48be1851e0d 100644
--- 
a/content/zh-cn/overview/mannual/java-sdk/advanced-features-and-usage/service/attachment.md
+++ 
b/content/zh-cn/overview/mannual/java-sdk/advanced-features-and-usage/service/attachment.md
@@ -109,3 +109,38 @@ public interface PenetrateAttachmentSelector {
 
 }
 ```
+
+# 历史遗留问题
+
+在之前的版本中,你可能会见到这样的使用方式:
+```java
+@Activate(group = {CommonConstants.CONSUMER})
+public class DubboConsumerFilter implements Filter {
+
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+        
+        RpcContext.getContext().setAttachment("demo","demo02");
+
+
+        return invoker.invoke(invocation);
+    }
+}
+```
+
+但是在新版本中我们的建议是 **在 Filter 里面的尽可能不要操作 
RpcContext**,上面的使用方式会导致不生效。原因在于新版本中,我们在`ConsumerContextFilter`类中做了`ClientAttachment`
 -> 
`Invocation`属性的复制,该类是Dubbo内置Filter类,而内置Filter类先于用户定义Filter类执行,所以在自定义Filter类中这样使用不会生效。
+可以直接使用这种方式进行传递:
+
+```java
+@Activate(group = {CommonConstants.CONSUMER})
+public class DubboConsumerFilter implements Filter {
+
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+        
+        invocation.setAttachment("demo","demo02");
+
+        return invoker.invoke(invocation);
+    }
+}
+```
diff --git a/content/zh-cn/overview/tasks/develop/context.md 
b/content/zh-cn/overview/tasks/develop/context.md
index 68f9c2db864..cb6a4c32425 100644
--- a/content/zh-cn/overview/tasks/develop/context.md
+++ b/content/zh-cn/overview/tasks/develop/context.md
@@ -66,4 +66,39 @@ public class ContextServiceImpl implements ContextService{
 ```
 
 *<font color='#FF7D00' size=4 > 注意 </font>*
-> path, group, version, dubbo, token, timeout 几个 key 是保留字段,请使用其它值。
\ No newline at end of file
+> path, group, version, dubbo, token, timeout 几个 key 是保留字段,请使用其它值。
+
+# 历史遗留问题
+
+在之前的版本中,你可能会见到这样的使用方式:
+```java
+@Activate(group = {CommonConstants.CONSUMER})
+public class DubboConsumerFilter implements Filter {
+
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+        
+        RpcContext.getContext().setAttachment("demo","demo02");
+
+
+        return invoker.invoke(invocation);
+    }
+}
+```
+
+但是在新版本中我们的建议是 **在 Filter 里面的尽可能不要操作 
RpcContext**,上面的使用方式会导致不生效。原因在于新版本中,我们在`ConsumerContextFilter`类中做了`ClientAttachment`
 -> 
`Invocation`属性的复制,该类是Dubbo内置Filter类,而内置Filter类先于用户定义Filter类执行,所以在自定义Filter类中这样使用不会生效。
+可以直接使用这种方式进行传递:
+
+```java
+@Activate(group = {CommonConstants.CONSUMER})
+public class DubboConsumerFilter implements Filter {
+
+    @Override
+    public Result invoke(Invoker<?> invoker, Invocation invocation) throws 
RpcException {
+        
+        invocation.setAttachment("demo","demo02");
+
+        return invoker.invoke(invocation);
+    }
+}
+```

Reply via email to