Skip to content

Commit

Permalink
Need use RpcInternalContext when subscribe event asynchronously. (s…
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjboy authored Apr 28, 2018
1 parent f0ad19f commit f10ee0e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alipay.sofa.rpc.common.RpcOptions;
import com.alipay.sofa.rpc.common.utils.CommonUtils;
import com.alipay.sofa.rpc.context.AsyncRuntime;
import com.alipay.sofa.rpc.context.RpcInternalContext;
import com.alipay.sofa.rpc.log.Logger;
import com.alipay.sofa.rpc.log.LoggerFactory;

Expand Down Expand Up @@ -117,11 +118,17 @@ public static void post(final Event event) {
if (subscriber.isSync()) {
handleEvent(subscriber, event);
} else { // 异步
final RpcInternalContext context = RpcInternalContext.peekContext();
AsyncRuntime.getAsyncThreadPool().execute(
new Runnable() {
@Override
public void run() {
handleEvent(subscriber, event);
try {
RpcInternalContext.setContext(context);
handleEvent(subscriber, event);
} catch (Exception e) {
RpcInternalContext.removeContext();
}
}
});
}
Expand Down

0 comments on commit f10ee0e

Please sign in to comment.