친애하는 gRPC/Spring 사용자 여러분, grpc-ecosystem/grpc-spring의 사용자 경험을 향상시키기 위해 우리는 직접적인 커뮤니케이션 라인을 구축하기 위한 수단으로 이 설문조사를 개발했습니다. 귀하의 의견을 높이 평가합니다.
읽어보기: 영어 | 중국어
문서: 영어 | 중국어
@GrpcService
구현을 사용하여 gRPC 서버를 자동으로 구성하고 실행합니다.
@GrpcClient
를 사용하여 grpc 채널과 스텁을 자동으로 생성하고 관리합니다.
다른 grpc-java 버전 지원(예: Reactive gRPC(RxJava), grpc-kotlin 등)
io.grpc.BindableService
기반).StubFactory
필요합니다.스프링 보안 지원
스프링 클라우드 지원
DiscoveryClient
(모든 버전)에서 서비스의 대상 주소를 읽습니다. 분산 추적 솔루션으로 Spring Sleuth 지원
(brave-instrumentation-grpc가 있는 경우)
전역 및 사용자 정의 gRPC 서버/클라이언트 인터셉터 지원
자동 미터법 지원(마이크로미터/액추에이터 기반)
(음영 처리되지 않은) grpc-netty에서도 작동합니다.
최신 버전은 3.1.0.RELEASE
이며 spring-boot 3.2.4
및 spring-cloud 2023.0.0
으로 컴파일되었지만 다양한 다른 버전과도 호환됩니다. 모든 버전과 해당 라이브러리 버전에 대한 개요는 당사 설명서에서 확인할 수 있습니다.
참고: 이 프로젝트는 Spring-Boot 없이도 사용할 수 있지만 일부 수동 Bean 구성이 필요합니다.
Maven을 사용하여 종속성을 추가하려면 다음을 사용하십시오.
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-spring-boot-starter</ artifactId >
< version >3.1.0.RELEASE</ version >
</ dependency >
Gradle을 사용하여 종속성을 추가하려면 다음 안내를 따르세요.
dependencies {
implementation ' net.devh:grpc-spring-boot-starter:3.1.0.RELEASE '
}
Maven을 사용하여 종속성을 추가하려면 다음을 사용하십시오.
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-server-spring-boot-starter</ artifactId >
< version >3.1.0.RELEASE</ version >
</ dependency >
Gradle을 사용하여 종속성을 추가하려면 다음 안내를 따르세요.
dependencies {
implementation ' net.devh:grpc-server-spring-boot-starter:3.1.0.RELEASE '
}
@GrpcService
로 서버 인터페이스 구현에 주석을 답니다.
@ GrpcService
public class GrpcServerService extends GreeterGrpc . GreeterImplBase {
@ Override
public void sayHello ( HelloRequest req , StreamObserver < HelloReply > responseObserver ) {
HelloReply reply = HelloReply . newBuilder (). setMessage ( "Hello ==> " + req . getName ()). build ();
responseObserver . onNext ( reply );
responseObserver . onCompleted ();
}
}
기본적으로 grpc 서버는 포트 9090
을 수신합니다. 이러한 설정과 기타 설정은 Spring의 속성 메커니즘을 통해 변경될 수 있습니다. 서버는 grpc.server.
접두사.
자세한 내용은 설명서를 참조하세요.
Maven을 사용하여 종속성을 추가하려면 다음을 사용하십시오.
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-client-spring-boot-starter</ artifactId >
< version >3.1.0.RELEASE</ version >
</ dependency >
Gradle을 사용하여 종속성을 추가하려면 다음 안내를 따르세요.
dependencies {
compile ' net.devh:grpc-client-spring-boot-starter:3.1.0.RELEASE '
}
@GrpcClient(serverName)
를 사용하여 grpc 클라이언트 스텁의 필드에 주석을 답니다.
@Autowired
또는 @Inject
와 함께 사용하지 마십시오.
@ GrpcClient ( "gRPC server name" )
private GreeterGrpc . GreeterBlockingStub greeterStub ;
참고: 여러 채널과 다른 스텁(다른 인터셉터가 있는 경우에도)에 동일한 grpc 서버 이름을 사용할 수 있습니다.
그런 다음 다음과 같이 서버에 쿼리를 보낼 수 있습니다.
HelloReply response = stub . sayHello ( HelloRequest . newBuilder (). setName ( name ). build ());
각 클라이언트의 대상 주소를 개별적으로 구성할 수 있습니다. 그러나 어떤 경우에는 기본 구성만 사용할 수 있습니다. NameResolver.Factory
빈을 통해 기본 URL 매핑을 사용자 정의할 수 있습니다. 해당 Bean을 구성하지 않으면 기본 구성표와 이름(예: dns:/<name>
)을 사용하여 기본 URI를 추측합니다.
이러한 설정과 기타 설정은 Spring의 속성 메커니즘을 통해 변경될 수 있습니다. 클라이언트는 grpc.client.(serverName).
접두사.
자세한 내용은 설명서를 참조하세요.
이 라이브러리는 grpc-netty
및 grpc-netty-shaded
모두 지원합니다. 후자는 호환되지 않는 grpc 버전과의 충돌이나 다른 버전의 netty가 필요한 라이브러리 간의 충돌을 방지할 수 있습니다.
참고: 음영 처리된 netty가 클래스 경로에 있는 경우 이 라이브러리는 항상 음영 처리되지 않은 grpc-netty보다 이를 선호합니다.
다음과 같이 Maven과 함께 사용할 수 있습니다.
< dependency >
< groupId >io.grpc</ groupId >
< artifactId >grpc-netty</ artifactId >
< version >${grpcVersion}</ version >
</ dependency >
<!-- For both -->
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-spring-boot-starter</ artifactId >
< version >...</ version >
< exclusions >
< exclusion >
< groupId >io.grpc</ groupId >
< artifactId >grpc-netty-shaded</ artifactId >
</ exclusion >
</ exclusions >
</ dependency >
<!-- For the server (only) -->
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-server-spring-boot-starter</ artifactId >
< version >...</ version >
< exclusions >
< exclusion >
< groupId >io.grpc</ groupId >
< artifactId >grpc-netty-shaded</ artifactId >
</ exclusion >
</ exclusions >
</ dependency >
<!-- For the client (only) -->
< dependency >
< groupId >net.devh</ groupId >
< artifactId >grpc-client-spring-boot-starter</ artifactId >
< version >...</ version >
< exclusions >
< exclusion >
< groupId >io.grpc</ groupId >
< artifactId >grpc-netty-shaded</ artifactId >
</ exclusion >
</ exclusions >
</ dependency >
Gradle을 사용할 때 다음과 같습니다.
implementation " io.grpc:grpc-netty: ${ grpcVersion } "
implementation ' net.devh:grpc-spring-boot-starter:... ' exclude group : ' io.grpc ' , module : ' grpc-netty-shaded ' // For both
implementation ' net.devh:grpc-client-spring-boot-starter:... ' exclude group : ' io.grpc ' , module : ' grpc-netty-shaded ' // For the client (only)
implementation ' net.devh:grpc-server-spring-boot-starter:... ' exclude group : ' io.grpc ' , module : ' grpc-netty-shaded ' // For the server (only)
여기에서 예시 프로젝트에 대해 자세히 알아보세요.
도움이 필요하면 설명서를 참조하세요.
기여는 언제나 환영합니다! 자세한 지침은 CONTRIBUTING.md를 참조하세요.