Class GrpcOutboundGateway

All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class GrpcOutboundGateway extends AbstractReplyProducingMessageHandler
The Outbound Gateway for gRPC client invocations.

This component acts as a gRPC stub where the request is based on the input message, the target gRPC service method to invoke is resolved at runtime based on a SpEL expression against the input message.

Supported gRPC requests:

  • Unary: Accepts a single request object
  • Server Streaming: Accepts a single request object
  • Client Streaming: Accepts Flux, Mono, Stream, Collection, or a single object
  • Bidirectional Streaming: Accepts Flux, Mono, Stream, Collection, or a single object
The request object must be of an expected domain entity generated from the respective service Protobuf.

Return type for the requests from the gateway:

  • Unary: Returns a Mono containing the response object by default. If AbstractMessageProducingHandler.isAsync() is set to false, it will return the response object.
  • Server Streaming: Returns a Flux of response messages
  • Client Streaming: Returns a Mono with the single response
  • Bidirectional Streaming: Returns a Flux of response messages

Since:
7.1
Author:
Glenn Renfro, Artem Bilan
  • Constructor Details

    • GrpcOutboundGateway

      public GrpcOutboundGateway(io.grpc.Channel channel, Class<?> grpcServiceClass)
      Create a new GrpcOutboundGateway based on the gRPC service class and Channel for communication. The gateway is set to async mode by default.
      Parameters:
      channel - the gRPC channel to use for communication
      grpcServiceClass - the gRPC service class (e.g., SimpleGrpc.class)
  • Method Details

    • setMethodNameExpression

      public void setMethodNameExpression(Expression methodNameExpression)
      Set the Expression to resolve the gRPC method name at runtime. If not provided, the default expression checks the MessageHeaders for a GrpcHeaders.SERVICE_METHOD. If the expression is not set and the service has only one method, then the gateway will set the expression to use the name of that method.
      Parameters:
      methodNameExpression - the expression to resolve the method name
    • setMethodName

      public void setMethodName(String methodName)
      Set the name of the gRPC method to call. If method name is not provided, the default expression checks the MessageHeaders for GrpcHeaders.SERVICE_METHOD or, in case a single service method, the name of that method is used.
      Parameters:
      methodName - the name of the gRPC method to call
    • setCallOptions

      public void setCallOptions(io.grpc.CallOptions callOptions)
      Set the CallOptions the RPC call. Default is CallOptions.DEFAULT
      Parameters:
      callOptions - the CallOptions for the gateway.
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • handleRequestMessage

      protected Object handleRequestMessage(Message<?> requestMessage)
      Description copied from class: AbstractReplyProducingMessageHandler
      Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.
      Specified by:
      handleRequestMessage in class AbstractReplyProducingMessageHandler
      Parameters:
      requestMessage - The request message.
      Returns:
      The result of handling the message, or null.