Skip to content

Commit

Permalink
Fix the problem that the consumer stub event does not trigger (#9723)
Browse files Browse the repository at this point in the history
related #9825.
  • Loading branch information
BurningCN committed Mar 28, 2022
1 parent 9579c2e commit feb1792
Showing 1 changed file with 21 additions and 3 deletions.
Expand Up @@ -181,13 +181,30 @@ private void invoke(Channel channel, String methodKey) {
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);
}
}
}

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
Expand Down Expand Up @@ -250,13 +267,14 @@ Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException
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);
Expand Down

0 comments on commit feb1792

Please sign in to comment.