Skip to content

Commit

Permalink
Fix Dubbo 2.7.5 compatibility problem of sentinel-apache-dubbo-adapter (
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyuguang authored Feb 21, 2020
1 parent 5f203aa commit 2bdeccf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sentinel-adapter/sentinel-apache-dubbo-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<apache.dubbo.version>2.7.3</apache.dubbo.version>
<apache.dubbo.version>2.7.5</apache.dubbo.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
import com.alibaba.csp.sentinel.context.ContextUtil;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ListenableFilter;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.*;

/**
* Base Class of the {@link SentinelDubboProviderFilter} and {@link SentinelDubboConsumerFilter}.
Expand All @@ -41,8 +37,16 @@ public BaseSentinelDubboFilter() {

static class SentinelDubboListener implements Listener {

@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
onSuccess(appResponse, invoker);
}

//for compatible dubbo 2.7.5 rename onResponse to onMessage
public void onMessage(Result appResponse, Invoker<?> invoker, Invocation invocation) {
onSuccess(appResponse, invoker);
}

private void onSuccess(Result appResponse, Invoker<?> invoker) {
if (DubboConfig.getDubboBizExceptionTraceEnabled()) {
traceAndExit(appResponse.getException(), invoker.getUrl());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public void testInvokeNullApplicationKey() {
verify(invoker).invoke(invocation);

String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY);
assertNull(application);
assertEquals(application, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public Result requestGo(boolean exception, Invocation currentInvocation) {
}

public Result responseBack(Result result) {
filter.listener().onResponse(result, invoker, invocation);
filter.listener().onMessage(result, invoker, invocation);
return result;
}

Expand Down Expand Up @@ -265,7 +265,7 @@ public void testInvokeSync() {
filter.invoke(invoker, invocation);
verify(invoker).invoke(invocation);

filter.listener().onResponse(result, invoker, invocation);
filter.listener().onMessage(result, invoker, invocation);
Context context = ContextUtil.getContext();
assertNull(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testInvoke() {
filter.invoke(invoker, invocation);
verify(invoker).invoke(invocation);

filter.listener().onResponse(result, invoker, invocation);
filter.listener().onMessage(result, invoker, invocation);
Context context = ContextUtil.getContext();
assertNull(context);
}
Expand Down

0 comments on commit 2bdeccf

Please sign in to comment.