Class SseQueryResponseSink
- All Implemented Interfaces:
QueryResponseSink
Each response is written as one event, whose data the container writes with the same message converters that write the body of any other response. Nothing is serialized here.
A write that fails is raised rather than swallowed: it means the member that asked is no longer reading, and the caller releases the query's response stream on the strength of it.
- Since:
- 5.4.0
- Author:
- Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionSseQueryResponseSink(org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) Constructs anSseQueryResponseSinkwriting to the givenemitter. -
Method Summary
Modifier and TypeMethodDescriptionvoidcomplete()Ends the response stream, reporting that the query was answered in full.voiderror(QueryDispatchFailure error) Ends the response stream, reporting that the query failed.voidWrites a comment, which carries nothing but keeps an otherwise idle stream from being closed.voidEnds the response stream, reporting that this member stops answering the subscription query because it is leaving the cluster.voidonUnavailable(Runnable listener) Registers alistenerto run once this sink can no longer be written to, for a reason other than the query having been answered — the member that asked stopped reading, or waited longer than it was given.voidresponse(QueryDispatchResponse response) Writes one response to the query being answered.voidsubscriptionComplete(String requestIdentifier) Reports that the subscription query being answered is over: there will never be another update to it.voidupdate(QueryDispatchResponse update) Writes one update to the subscription query being answered.
-
Constructor Details
-
SseQueryResponseSink
public SseQueryResponseSink(org.springframework.web.servlet.mvc.method.annotation.SseEmitter emitter) Constructs anSseQueryResponseSinkwriting to the givenemitter.- Parameters:
emitter- the emitter carrying the response stream to the member that asked
-
-
Method Details
-
response
Description copied from interface:QueryResponseSinkWrites one response to the query being answered.- Specified by:
responsein interfaceQueryResponseSink- Parameters:
response- the response to write
-
update
Description copied from interface:QueryResponseSinkWrites one update to the subscription query being answered.Distinct from
QueryResponseSink.response(QueryDispatchResponse)because the subscriber acts on the two differently: a response belongs to the initial result, an update is a change after it.- Specified by:
updatein interfaceQueryResponseSink- Parameters:
update- the update to write
-
subscriptionComplete
Description copied from interface:QueryResponseSinkReports that the subscription query being answered is over: there will never be another update to it.Distinct from
QueryResponseSink.leaving(String), which says only that this member stops answering, and from the stream merely ending, which fails the subscription. This says the subscription itself has run its course, and the subscriber stops waiting on every other member too.- Specified by:
subscriptionCompletein interfaceQueryResponseSink- Parameters:
requestIdentifier- the identifier of the subscription query that is over
-
leaving
Description copied from interface:QueryResponseSinkEnds the response stream, reporting that this member stops answering the subscription query because it is leaving the cluster.Distinct from
QueryResponseSink.subscriptionComplete(String), which ends the subscription for every member, and fromQueryResponseSink.error(QueryDispatchFailure), which fails it. This ends only this member's part: it has stopped emitting updates, so the subscriber carries on with the members that remain. Also distinct from the stream merely ending, which the subscriber cannot tell apart from a lost connection and so treats as a failure.- Specified by:
leavingin interfaceQueryResponseSink- Parameters:
requestIdentifier- the identifier of the subscription query this member stops answering
-
error
Description copied from interface:QueryResponseSinkEnds the response stream, reporting that the query failed.- Specified by:
errorin interfaceQueryResponseSink- Parameters:
error- the failure that ended the response stream
-
complete
public void complete()Description copied from interface:QueryResponseSinkEnds the response stream, reporting that the query was answered in full.- Specified by:
completein interfaceQueryResponseSink
-
keepAlive
public void keepAlive()Writes a comment, which carries nothing but keeps an otherwise idle stream from being closed.A subscription query may go a long time without producing an update, and an idle connection is what a load balancer, proxy or NAT table reclaims. A comment is the Server-Sent Events way of saying nothing: a reader following the specification discards it, and this member learns the subscriber is gone when the write fails.
- Throws:
ResponseStreamClosedException- when the member that asked has stopped reading