1616
1717package org .springframework .integration .samples .grpc .client ;
1818
19+ import java .util .Collections ;
20+
1921import io .grpc .ManagedChannel ;
2022import org .apache .commons .logging .Log ;
2123import org .apache .commons .logging .LogFactory ;
3032import org .springframework .integration .channel .FluxMessageChannel ;
3133import org .springframework .integration .core .MessagingTemplate ;
3234import org .springframework .integration .dsl .IntegrationFlow ;
35+ import org .springframework .integration .grpc .GrpcHeaders ;
3336import org .springframework .integration .grpc .dsl .Grpc ;
3437import org .springframework .integration .support .MessageBuilder ;
3538import org .springframework .messaging .Message ;
@@ -47,7 +50,7 @@ public class GrpcClientConfiguration {
4750
4851 @ Bean
4952 ManagedChannel managedChannel (GrpcChannelFactory factory ) {
50- return factory .createChannel ("local " );
53+ return factory .createChannel ("spring-integration " );
5154 }
5255
5356 /**
@@ -58,8 +61,7 @@ ManagedChannel managedChannel(GrpcChannelFactory factory) {
5861 @ Bean
5962 IntegrationFlow grpcOutboundFlowSingleResponse (ManagedChannel managedChannel ) {
6063 return flow -> flow
61- .handle (Grpc .outboundGateway (managedChannel , SimpleGrpc .class )
62- .methodName ("SayHello" ));
64+ .handle (Grpc .outboundGateway (managedChannel , SimpleGrpc .class ));
6365 }
6466
6567 /**
@@ -70,8 +72,7 @@ IntegrationFlow grpcOutboundFlowSingleResponse(ManagedChannel managedChannel) {
7072 @ Bean
7173 IntegrationFlow grpcOutboundFlowStreamResponse (ManagedChannel managedChannel ) {
7274 return flow -> flow
73- .handle (Grpc .outboundGateway (managedChannel , SimpleGrpc .class )
74- .methodName ("StreamHello" ));
75+ .handle (Grpc .outboundGateway (managedChannel , SimpleGrpc .class ));
7576 }
7677
7778 /**
@@ -86,6 +87,7 @@ ApplicationRunner grpcClientSingleResponse(
8687 return args -> {
8788 HelloReply reply = new MessagingTemplate ().convertSendAndReceive (grpcInputChannelSingleResponse ,
8889 HelloRequest .newBuilder ().setName ("Jack" ).build (),
90+ Collections .singletonMap (GrpcHeaders .SERVICE_METHOD , "SayHello" ),
8991 HelloReply .class );
9092
9193 LOGGER .info ("Single response reply: " + (reply != null ? reply .getMessage () : "No reply received" ));
@@ -115,6 +117,7 @@ ApplicationRunner grpcClientStreamResponse(
115117 Message <?> requestMessage = MessageBuilder
116118 .withPayload (HelloRequest .newBuilder ().setName ("Jane" ).build ())
117119 .setReplyChannel (grpcStreamOutputChannel )
120+ .setHeader (GrpcHeaders .SERVICE_METHOD , "StreamHello" )
118121 .build ();
119122 grpcInputChannel .send (requestMessage );
120123 };
0 commit comments