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

liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new feb1792  Fix the problem that the consumer stub event does not trigger 
(#9723)
feb1792 is described below

commit feb1792b634e44005c0dacaa7fcb981c12de931f
Author: 灼华 <[email protected]>
AuthorDate: Mon Mar 28 17:31:12 2022 +0800

    Fix the problem that the consumer stub event does not trigger (#9723)
    
    related #9825.
---
 .../dubbo/rpc/protocol/dubbo/DubboProtocol.java    | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
 
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
index 1d784f4..c34e0ba 100644
--- 
a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
+++ 
b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java
@@ -181,6 +181,9 @@ public class DubboProtocol extends AbstractProtocol {
             Invocation invocation = createInvocation(channel, 
channel.getUrl(), methodKey);
             if (invocation != null) {
                 try {
+                    if 
(Boolean.TRUE.toString().equals(invocation.getAttachment(STUB_EVENT_KEY))) {
+                        tryToGetStubService(channel, invocation);
+                    }
                     received(channel, invocation);
                 } catch (Throwable t) {
                     logger.warn("Failed to invoke event method " + 
invocation.getMethodName() + "(), cause: " + t.getMessage(), t);
@@ -188,6 +191,20 @@ public class DubboProtocol extends AbstractProtocol {
             }
         }
 
+        private void tryToGetStubService(Channel channel, Invocation 
invocation) throws RemotingException {
+            try {
+                Invoker<?> invoker = getInvoker(channel, invocation);
+            } catch (RemotingException e) {
+                String serviceKey = serviceKey(
+                    0,
+                    (String) invocation.getObjectAttachments().get(PATH_KEY),
+                    (String) 
invocation.getObjectAttachments().get(VERSION_KEY),
+                    (String) invocation.getObjectAttachments().get(GROUP_KEY)
+                );
+                throw new RemotingException(channel, "The stub service[" + 
serviceKey + "] is not found, it may not be exported yet");
+            }
+        }
+
         /**
          * FIXME channel.getUrl() always binds to a fixed service, and this 
service is random.
          * we can choose to use a common service to carry onConnect event if 
there's no easy way to get the specific
@@ -250,13 +267,14 @@ public class DubboProtocol extends AbstractProtocol {
         int port = channel.getLocalAddress().getPort();
         String path = (String) inv.getObjectAttachments().get(PATH_KEY);
 
-        // if it's callback service on client side
+        //if it's stub service on client side(after enable stubevent, usually 
is set up onconnect or ondisconnect method)
         isStubServiceInvoke = 
Boolean.TRUE.toString().equals(inv.getObjectAttachments().get(STUB_EVENT_KEY));
         if (isStubServiceInvoke) {
-            port = channel.getRemoteAddress().getPort();
+            //when a stub service export to local, it usually can't be exposed 
to port
+            port = 0;
         }
 
-        //callback
+        // if it's callback service on client side
         isCallBackServiceInvoke = isClientSide(channel) && 
!isStubServiceInvoke;
         if (isCallBackServiceInvoke) {
             path += "." + inv.getObjectAttachments().get(CALLBACK_SERVICE_KEY);

Reply via email to