forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE alibaba#5361] add a GrpcRequestFilter to check isUseGrpcFeatur…
…es() when using GRPC protocol
- Loading branch information
Showing
3 changed files
with
27 additions
and
18 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
naming/src/main/java/com/alibaba/nacos/naming/remote/rpc/filter/GrpcRequestFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.alibaba.nacos.naming.remote.rpc.filter; | ||
|
||
import com.alibaba.nacos.api.exception.NacosException; | ||
import com.alibaba.nacos.api.remote.request.Request; | ||
import com.alibaba.nacos.api.remote.request.RequestMeta; | ||
import com.alibaba.nacos.api.remote.response.Response; | ||
import com.alibaba.nacos.core.remote.AbstractRequestFilter; | ||
import com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class GrpcRequestFilter extends AbstractRequestFilter { | ||
|
||
@Autowired | ||
private UpgradeJudgement upgradeJudgement; | ||
|
||
@Override | ||
protected Response filter(Request request, RequestMeta meta, Class handlerClazz) throws NacosException { | ||
if (!upgradeJudgement.isUseGrpcFeatures()) { | ||
Response response = getDefaultResponseInstance(handlerClazz); | ||
response.setErrorInfo(NacosException.SERVER_ERROR, "Nacos cluster is running with 1.X mode, can't accept gRPC request temporarily. Please check the server status or close Double write to force open 2.0 mode. Detail https://nacos.io/en-us/docs/2.0.0-upgrading.html."); | ||
return response; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters