Class GrpcOutboundGateway
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.handler.AbstractMessageProducingHandler
org.springframework.integration.handler.AbstractReplyProducingMessageHandler
org.springframework.integration.grpc.outbound.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<?>>
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
Return type for the requests from the gateway:
- Unary: Returns a
Monocontaining the response object by default. IfAbstractMessageProducingHandler.isAsync()is set to false, it will return the response object. - Server Streaming: Returns a
Fluxof response messages - Client Streaming: Returns a
Monowith the single response - Bidirectional Streaming: Returns a
Fluxof response messages
- Since:
- 7.1
- Author:
- Glenn Renfro, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandlerNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionGrpcOutboundGateway(io.grpc.Channel channel, Class<?> grpcServiceClass) Create a newGrpcOutboundGatewaybased on the gRPC service class andChannelfor communication. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoInit()protected ObjecthandleRequestMessage(Message<?> requestMessage) Subclasses must implement this method to handle the request Message.voidsetCallOptions(io.grpc.CallOptions callOptions) Set theCallOptionsthe RPC call.voidsetMethodName(String methodName) Set the name of the gRPC method to call.voidsetMethodNameExpression(Expression methodNameExpression) Set theExpressionto resolve the gRPC method name at runtime.Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
doInvokeAdvisedRequestHandler, getBeanClassLoader, getIntegrationPatternType, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReplyMethods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldCopyRequestHeaders, shouldSplitOutput, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getComponentType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
GrpcOutboundGateway
Create a newGrpcOutboundGatewaybased on the gRPC service class andChannelfor communication. The gateway is set to async mode by default.- Parameters:
channel- the gRPC channel to use for communicationgrpcServiceClass- the gRPC service class (e.g.,SimpleGrpc.class)
-
-
Method Details
-
setMethodNameExpression
Set theExpressionto resolve the gRPC method name at runtime. If not provided, the default expression checks theMessageHeadersfor aGrpcHeaders.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
Set the name of the gRPC method to call. If method name is not provided, the default expression checks theMessageHeadersforGrpcHeaders.SERVICE_METHODor, 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 theCallOptionsthe RPC call. Default isCallOptions.DEFAULT- Parameters:
callOptions- theCallOptionsfor the gateway.
-
doInit
protected void doInit()- Overrides:
doInitin classAbstractReplyProducingMessageHandler
-
handleRequestMessage
Description copied from class:AbstractReplyProducingMessageHandlerSubclasses 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:
handleRequestMessagein classAbstractReplyProducingMessageHandler- Parameters:
requestMessage- The request message.- Returns:
- The result of handling the message, or
null.
-