Interface GrpcBaseExchange<A extends ExchangeContext,B,C>
- Type Parameters:
A
- The exchange context typeB
- The request typeC
- The response type
- All Known Subinterfaces:
GrpcExchange<A,
,B, C, D, E> GrpcExchange<A,
,B, C, D, E> GrpcExchange.BidirectionalStreaming<A,
,B, C> GrpcExchange.BidirectionalStreaming<A,
,B, C> GrpcExchange.ClientStreaming<A,
,B, C> GrpcExchange.ClientStreaming<A,
,B, C> GrpcExchange.ServerStreaming<A,
,B, C> GrpcExchange.ServerStreaming<A,
,B, C> GrpcExchange.Unary<A,
,B, C> GrpcExchange.Unary<A,
B, C>
Base gRPC exchange (request/response) for representing server or client exchanges.
A gRPC exchange basically comes down to a request
and a response
being exchanged between a client and a server. In a client exchange, the client sends the
request to the server and receives the response from the server. In a server exchange, the server receives the request from the client and sends the response to the client.
A context
is also attached to every exchange to provide contextual data and operation during during the processing of the exchange.
- Since:
- 1.9
- Author:
- Jeremy Kuhn
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancels the exchange.context()
Returns the context attached to the exchange.Returns the error that caused the cancellation of the exchange.request()
Returns the gRPC request part of the exchange.response()
Returns the gRPC response part of the exchange.
-
Method Details
-
context
A context()Returns the context attached to the exchange.
- Returns:
- the exchange context or null
-
request
B request()Returns the gRPC request part of the exchange.
- Returns:
- the gRPC request part
-
response
C response()Returns the gRPC response part of the exchange.
- Returns:
- the gRPC response part
-
cancel
void cancel()Cancels the exchange.
This method is typically invoked to cancel the exchange (i.e. stop processing) as defined by gRPC Cancellation by immediately cancelling active subscription to the response data publisher.
This will result in the underlying HTTP/2 stream being reset with a
CANCEL(0x8)
HTTP/2 error code as defined by RFC 7540 Section 7. -
getCancelCause
Optional<GrpcException> getCancelCause()Returns the error that caused the cancellation of the exchange.
Exchange disposal resulting or not from an error is usually catched in the request data publisher which can be bound to the response data publisher in which case, errors can then be catched by defining
Flux.doOnError(java.util.function.Consumer)
on the response data publisher. When the request data publisher is not consumed, terminated and not bound to the response data publisher, the response data publisher is disposed without error, this method gives access to the error when catching the exchange disposal by definingFlux.doOnCancel(java.lang.Runnable)
.- Returns:
- an optional returning the cancel error or an empty optional if the exchange hasn't been disposed or if it completed successfully (when both request and response data publishers completed successfully)
-