io.grpc.StatusRuntimeException: UNIMPLEMENTED: Method not found

本文记录了使用 gRPC 时遇到的“Methodnotfound”错误,并提供了详细的堆栈跟踪。该错误发生在尝试调用 BusinessRecommendService 的 query 方法时。解决方法包括重启服务端并使用 run 而不是 debug 模式。

今天真无语,用grpc搞了很久,遇到这个错

 Method not found: BusinessRecommendService/query
    at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:227)
    at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:208)
    at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:141)
    at cn.vpclub.mcs.shake.admin.api.BusinessRecommendServiceGrpc$BusinessRecommendServiceBlockingStub.query(BusinessRecommendServiceGrpc.java:328)
    at cn.vpclub.mcs.shake.admin.rpc.BusinessRecommendRpcService.query(BusinessRecommendRpcService.java:61)
    at cn.vpclub.mcs.shake.admin.service.BusinessRecommendService.query(BusinessRecommendService.java:202)
    at cn.vpclub.mcs.shake.admin.web.BusinessRecommendController.query(BusinessRecommendController.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.SessionRestoringHandler.handleRequest(SessionRestoringHandler.java:119)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
    at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:211)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:809)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)


答案就是:重启服务端,注意如果不行,就不要用debug启动,用run,再试试,坑人不眨眼啊

"C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\bin\java.exe" "-javaagent:D:\IntelliJ IDEA Community Edition 2025.1.4.1\lib\idea_rt.jar=57570" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\charsets.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\dnsns.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\jaccess.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\localedata.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\nashorn.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\sunec.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\ext\zipfs.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\jce.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\jfr.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\jfxswt.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\jsse.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\management-agent.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\resources.jar;C:\Program Files\Java\openlogic-openjdk-8u462-b08-windows-x64\jre\lib\rt.jar;D:\r\basic-spring-boot\target\classes;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-validation\2.1.14.RELEASE\spring-boot-starter-validation-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.14.RELEASE\spring-boot-starter-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot\2.1.14.RELEASE\spring-boot-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.14.RELEASE\spring-boot-autoconfigure-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.14.RELEASE\spring-boot-starter-logging-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\admin\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\admin\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\admin\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\admin\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\admin\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\admin\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.34\tomcat-embed-el-9.0.34.jar;C:\Users\admin\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.19.Final\hibernate-validator-6.0.19.Final.jar;C:\Users\admin\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\admin\.m2\repository\org\jboss\logging\jboss-logging\3.3.3.Final\jboss-logging-3.3.3.Final.jar;C:\Users\admin\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.1.14.RELEASE\spring-boot-starter-data-jpa-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.14.RELEASE\spring-boot-starter-jdbc-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;C:\Users\admin\.m2\repository\org\springframework\spring-jdbc\5.1.15.RELEASE\spring-jdbc-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\javax\transaction\javax.transaction-api\1.3\javax.transaction-api-1.3.jar;C:\Users\admin\.m2\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\admin\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\admin\.m2\repository\org\hibernate\hibernate-core\5.3.17.Final\hibernate-core-5.3.17.Final.jar;C:\Users\admin\.m2\repository\javax\persistence\javax.persistence-api\2.2\javax.persistence-api-2.2.jar;C:\Users\admin\.m2\repository\org\javassist\javassist\3.23.2-GA\javassist-3.23.2-GA.jar;C:\Users\admin\.m2\repository\net\bytebuddy\byte-buddy\1.9.16\byte-buddy-1.9.16.jar;C:\Users\admin\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\admin\.m2\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;C:\Users\admin\.m2\repository\org\dom4j\dom4j\2.1.3\dom4j-2.1.3.jar;C:\Users\admin\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.4.Final\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\admin\.m2\repository\org\glassfish\jaxb\jaxb-runtime\2.3.1\jaxb-runtime-2.3.1.jar;C:\Users\admin\.m2\repository\org\glassfish\jaxb\txw2\2.3.1\txw2-2.3.1.jar;C:\Users\admin\.m2\repository\com\sun\istack\istack-commons-runtime\3.0.7\istack-commons-runtime-3.0.7.jar;C:\Users\admin\.m2\repository\org\jvnet\staxex\stax-ex\1.8\stax-ex-1.8.jar;C:\Users\admin\.m2\repository\com\sun\xml\fastinfoset\FastInfoset\1.2.15\FastInfoset-1.2.15.jar;C:\Users\admin\.m2\repository\org\springframework\data\spring-data-jpa\2.1.17.RELEASE\spring-data-jpa-2.1.17.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\data\spring-data-commons\2.1.17.RELEASE\spring-data-commons-2.1.17.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-orm\5.1.15.RELEASE\spring-orm-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-context\5.1.15.RELEASE\spring-context-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-tx\5.1.15.RELEASE\spring-tx-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-beans\5.1.15.RELEASE\spring-beans-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\admin\.m2\repository\org\springframework\spring-aspects\5.1.15.RELEASE\spring-aspects-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\com\mysql\mysql-connector-j\8.2.0\mysql-connector-j-8.2.0.jar;C:\Users\admin\.m2\repository\com\google\protobuf\protobuf-java\3.21.9\protobuf-java-3.21.9.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.14.RELEASE\spring-boot-starter-web-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.14.RELEASE\spring-boot-starter-json-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.10.4\jackson-databind-2.9.10.4.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.10\jackson-annotations-2.9.10.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.10\jackson-core-2.9.10.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.10\jackson-datatype-jdk8-2.9.10.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.10\jackson-datatype-jsr310-2.9.10.jar;C:\Users\admin\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.10\jackson-module-parameter-names-2.9.10.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.14.RELEASE\spring-boot-starter-tomcat-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.34\tomcat-embed-core-9.0.34.jar;C:\Users\admin\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.34\tomcat-embed-websocket-9.0.34.jar;C:\Users\admin\.m2\repository\org\springframework\spring-web\5.1.15.RELEASE\spring-web-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-webmvc\5.1.15.RELEASE\spring-webmvc-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-expression\5.1.15.RELEASE\spring-expression-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.1.14.RELEASE\spring-boot-starter-aop-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-aop\5.1.15.RELEASE\spring-aop-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\aspectj\aspectjweaver\1.9.5\aspectjweaver-1.9.5.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.1.14.RELEASE\spring-boot-starter-actuator-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.1.14.RELEASE\spring-boot-actuator-autoconfigure-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\boot\spring-boot-actuator\2.1.14.RELEASE\spring-boot-actuator-2.1.14.RELEASE.jar;C:\Users\admin\.m2\repository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;C:\Users\admin\.m2\repository\org\springframework\spring-core\5.1.15.RELEASE\spring-core-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\org\springframework\spring-jcl\5.1.15.RELEASE\spring-jcl-5.1.15.RELEASE.jar;C:\Users\admin\.m2\repository\com\alibaba\fastjson2\fastjson2\2.0.23\fastjson2-2.0.23.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-netty-shaded\1.56.0\grpc-netty-shaded-1.56.0.jar;C:\Users\admin\.m2\repository\com\google\guava\guava\31.1-android\guava-31.1-android.jar;C:\Users\admin\.m2\repository\com\google\guava\failureaccess\1.0.1\failureaccess-1.0.1.jar;C:\Users\admin\.m2\repository\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\admin\.m2\repository\org\checkerframework\checker-qual\3.12.0\checker-qual-3.12.0.jar;C:\Users\admin\.m2\repository\com\google\j2objc\j2objc-annotations\1.3\j2objc-annotations-1.3.jar;C:\Users\admin\.m2\repository\com\google\errorprone\error_prone_annotations\2.18.0\error_prone_annotations-2.18.0.jar;C:\Users\admin\.m2\repository\io\perfmark\perfmark-api\0.26.0\perfmark-api-0.26.0.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-protobuf\1.56.0\grpc-protobuf-1.56.0.jar;C:\Users\admin\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar;C:\Users\admin\.m2\repository\com\google\api\grpc\proto-google-common-protos\2.17.0\proto-google-common-protos-2.17.0.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-protobuf-lite\1.56.0\grpc-protobuf-lite-1.56.0.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-stub\1.56.0\grpc-stub-1.56.0.jar;C:\Users\admin\.m2\repository\net\devh\grpc-spring-boot-starter\2.14.0.RELEASE\grpc-spring-boot-starter-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\net\devh\grpc-server-spring-boot-starter\2.14.0.RELEASE\grpc-server-spring-boot-starter-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\net\devh\grpc-server-spring-boot-autoconfigure\2.14.0.RELEASE\grpc-server-spring-boot-autoconfigure-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\net\devh\grpc-common-spring-boot\2.14.0.RELEASE\grpc-common-spring-boot-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-core\1.51.0\grpc-core-1.51.0.jar;C:\Users\admin\.m2\repository\com\google\code\gson\gson\2.8.6\gson-2.8.6.jar;C:\Users\admin\.m2\repository\com\google\android\annotations\4.1.1.4\annotations-4.1.1.4.jar;C:\Users\admin\.m2\repository\org\codehaus\mojo\animal-sniffer-annotations\1.21\animal-sniffer-annotations-1.21.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-services\1.51.0\grpc-services-1.51.0.jar;C:\Users\admin\.m2\repository\com\google\protobuf\protobuf-java-util\3.21.7\protobuf-java-util-3.21.7.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-api\1.51.0\grpc-api-1.51.0.jar;C:\Users\admin\.m2\repository\io\grpc\grpc-context\1.51.0\grpc-context-1.51.0.jar;C:\Users\admin\.m2\repository\net\devh\grpc-client-spring-boot-starter\2.14.0.RELEASE\grpc-client-spring-boot-starter-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\net\devh\grpc-client-spring-boot-autoconfigure\2.14.0.RELEASE\grpc-client-spring-boot-autoconfigure-2.14.0.RELEASE.jar;C:\Users\admin\.m2\repository\io\micrometer\micrometer-core\1.11.4\micrometer-core-1.11.4.jar;C:\Users\admin\.m2\repository\io\micrometer\micrometer-commons\1.11.4\micrometer-commons-1.11.4.jar;C:\Users\admin\.m2\repository\io\micrometer\micrometer-observation\1.11.4\micrometer-observation-1.11.4.jar;C:\Users\admin\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.12\HdrHistogram-2.1.12.jar;C:\Users\admin\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar" com.tplink.nbu.demo.basicspringboot.GrpcClient 11:38:31.760 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework 11:38:31.764 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false 11:38:31.764 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - Java version: 8 11:38:31.764 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.storeFence: available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - direct buffer constructor: available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - java.nio.Bits.unaligned: available, true 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent0 - java.nio.DirectByteBuffer.<init>(long, int): available 11:38:31.765 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - sun.misc.Unsafe: available 11:38:31.766 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - -Dio.netty.tmpdir: C:\Users\admin\AppData\Local\Temp (java.io.tmpdir) 11:38:31.766 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - -Dio.netty.bitMode: 64 (sun.arch.data.model) 11:38:31.766 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - Platform: Windows 11:38:31.767 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - -Dio.netty.maxDirectMemory: 7570718720 bytes 11:38:31.767 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - -Dio.netty.uninitializedArrayAllocationThreshold: -1 11:38:31.767 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.CleanerJava6 - java.nio.ByteBuffer.cleaner(): available 11:38:31.767 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - -Dio.netty.noPreferDirect: false 11:38:31.905 [main] DEBUG io.grpc.netty.shaded.io.netty.channel.MultithreadEventLoopGroup - -Dio.netty.eventLoopThreads: 48 11:38:31.912 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.initialSize: 1024 11:38:31.912 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.InternalThreadLocalMap - -Dio.netty.threadLocalMap.stringBuilder.maxSize: 4096 11:38:31.915 [main] DEBUG io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop - -Dio.netty.noKeySetOptimization: false 11:38:31.915 [main] DEBUG io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop - -Dio.netty.selectorAutoRebuildThreshold: 512 11:38:31.918 [main] DEBUG io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent - org.jctools-core.MpscChunkedArrayQueue: available 11:38:32.087 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.ResourceLeakDetector - -Dio.grpc.netty.shaded.io.netty.leakDetection.level: simple 11:38:32.087 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.ResourceLeakDetector - -Dio.grpc.netty.shaded.io.netty.leakDetection.targetRecords: 4 11:38:32.090 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.AbstractByteBuf - -Dio.grpc.netty.shaded.io.netty.buffer.checkAccessible: true 11:38:32.090 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.AbstractByteBuf - -Dio.grpc.netty.shaded.io.netty.buffer.checkBounds: true 11:38:32.090 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.ResourceLeakDetectorFactory - Loaded default ResourceLeakDetector: io.grpc.netty.shaded.io.netty.util.ResourceLeakDetector@7f0df18 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numHeapArenas: 48 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.numDirectArenas: 48 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.pageSize: 8192 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxOrder: 9 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.chunkSize: 4194304 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.smallCacheSize: 256 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.normalCacheSize: 64 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedBufferCapacity: 32768 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimInterval: 8192 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.cacheTrimIntervalMillis: 0 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.useCacheForAllThreads: false 11:38:32.117 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023 11:38:32.135 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.channel.DefaultChannelId - -Dio.netty.processId: 8460 (auto-detected) 11:38:32.136 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.NetUtil - -Djava.net.preferIPv4Stack: false 11:38:32.136 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.NetUtil - -Djava.net.preferIPv6Addresses: false 11:38:32.176 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.NetUtilInitializations - Loopback interface: lo (Software Loopback Interface 1, 127.0.0.1) 11:38:32.176 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.NetUtil - Failed to get SOMAXCONN from sysctl and file \proc\sys\net\core\somaxconn. Default: 200 11:38:32.179 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.channel.DefaultChannelId - -Dio.netty.machineId: a0:ad:9f:ff:fe:1d:8c:93 (auto-detected) 11:38:32.189 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled 11:38:32.189 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0 11:38:32.189 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384 11:38:32.196 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.Recycler - -Dio.netty.recycler.maxCapacityPerThread: 4096 11:38:32.196 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.Recycler - -Dio.netty.recycler.ratio: 8 11:38:32.196 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.Recycler - -Dio.netty.recycler.chunkSize: 32 11:38:32.196 [grpc-default-executor-0] DEBUG io.grpc.netty.shaded.io.netty.util.Recycler - -Dio.netty.recycler.blocking: false 11:38:32.207 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND SETTINGS: ack=false settings={ENABLE_PUSH=0, MAX_CONCURRENT_STREAMS=0, INITIAL_WINDOW_SIZE=1048576, MAX_HEADER_LIST_SIZE=8192} 11:38:32.211 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND WINDOW_UPDATE: streamId=0 windowSizeIncrement=983041 11:38:32.256 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] INBOUND SETTINGS: ack=false settings={MAX_CONCURRENT_STREAMS=2147483647, INITIAL_WINDOW_SIZE=1048576, MAX_HEADER_LIST_SIZE=8192} 11:38:32.257 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND SETTINGS: ack=true 11:38:32.265 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] INBOUND WINDOW_UPDATE: streamId=0 windowSizeIncrement=983041 11:38:32.266 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] INBOUND SETTINGS: ack=true 11:38:32.271 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND HEADERS: streamId=3 headers=GrpcHttp2OutboundHeaders[:authority: localhost:9090, :path: /UserGrpcService/Register, :method: POST, :scheme: http, content-type: application/grpc, te: trailers, user-agent: grpc-java-netty/1.51.0, grpc-accept-encoding: gzip] streamDependency=0 weight=16 exclusive=false padding=0 endStream=false 11:38:32.277 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND DATA: streamId=3 padding=0 endStream=true length=49 bytes=000000002c0a08746573745573657212063132333435361a1074657374406578616d706c652e636f6d2206e58c97e4baac 11:38:32.302 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] INBOUND PING: ack=false bytes=1234 11:38:32.302 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] OUTBOUND PING: ack=true bytes=1234 11:38:32.308 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xf85c2e3d, L:/127.0.0.1:57623 - R:localhost/127.0.0.1:9090] INBOUND HEADERS: streamId=3 headers=GrpcHttp2ResponseHeaders[:status: 200, content-type: application/grpc, grpc-status: 12, grpc-message: Method not found: UserGrpcService/Register] padding=0 endStream=true 【注册失败】原因:Method not found: UserGrpcService/Register,请分析并修改,源代码如下public class GrpcClient { private final ManagedChannel channel; private final UserGrpcServiceGrpc.UserGrpcServiceFutureStub futureStub; private final CountDownLatch latch = new CountDownLatch(3); public GrpcClient(String host, int port) { this.channel = ManagedChannelBuilder.forAddress(host, port) .usePlaintext() .build(); this.futureStub = UserGrpcServiceGrpc.newFutureStub(channel); } // 异步注册(触发后续登录) public void asyncRegister(String username, String password, String email, String address) { UserRegisterRequest request = UserRegisterRequest.newBuilder() .setUsername(username) .setPassword(password) .setEmail(email) .setAddress(address) .build(); ListenableFuture<UserRegisterResponse> responseFuture = futureStub.register(request); responseFuture.addListener(() -> { try { UserRegisterResponse response = responseFuture.get(); System.out.println("【注册结果】成功:" + response.getSuccess() + ",消息:" + response.getMessage()); if (response.getSuccess()) { // 注册成功后触发登录(使用相同邮箱和密码) asyncLogin(email, password); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println("【注册中断】原因:" + e.getMessage()); } catch (ExecutionException e) { Status status = Status.fromThrowable(e.getCause()); System.err.println("【注册失败】原因:" + status.getDescription()); } finally { latch.countDown(); // 注册操作完成 } }, MoreExecutors.directExecutor()); } // 异步登录(触发后续登出) private void asyncLogin(String email, String password) { UserLoginRequest request = UserLoginRequest.newBuilder() .setEmail(email) .setPassword(password) .build(); ListenableFuture<UserLoginResponse> responseFuture = futureStub.login(request); responseFuture.addListener(() -> { try { UserLoginResponse response = responseFuture.get(); System.out.println("【登录结果】token:" + response.getToken() + ",用户ID:" + response.getUserId()); if (!response.getToken().isEmpty()) { // 登录成功后触发登出 asyncLogout(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println("【登录中断】原因:" + e.getMessage()); } catch (ExecutionException e) { Status status = Status.fromThrowable(e.getCause()); System.err.println("【登录失败】原因:" + status.getDescription()); } finally { latch.countDown(); // 登录操作完成 } }, MoreExecutors.directExecutor()); } // 异步登出 private void asyncLogout() { UserLogoutRequest request = UserLogoutRequest.newBuilder().build(); ListenableFuture<UserLogoutResponse> responseFuture = futureStub.logout(request); responseFuture.addListener(() -> { try { UserLogoutResponse response = responseFuture.get(); System.out.println("【登出结果】成功:" + response.getSuccess() + ",消息:" + response.getMessage()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println("【登出中断】原因:" + e.getMessage()); } catch (ExecutionException e) { Status status = Status.fromThrowable(e.getCause()); System.err.println("【登出失败】原因:" + status.getDescription()); } finally { latch.countDown(); // 登出操作完成 } }, MoreExecutors.directExecutor()); } // 等待所有操作完成后关闭通道 public void shutdown() throws InterruptedException { latch.await(); // 阻塞直到所有操作完成 channel.shutdown(); } public static void main(String[] args) throws InterruptedException { GrpcClient client = new GrpcClient("localhost", 9090); // 启动注册流程(触发后续登录、登出) client.asyncRegister("testUser", "123456", "test@example.com", "北京"); // 等待所有操作完成后关闭客户端 client.shutdown(); } }
最新发布
08-26
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值