Interface MutinyEmitter<T>
-
- Type Parameters:
T- type of payload
- All Known Implementing Classes:
MutinyEmitterImpl
public interface MutinyEmitter<T>Interface used to feed a channel from an imperative piece of code.Instances are injected using:
@Inject @Channel("my-channel") MutinyEmitter<String> emitter;You can use an injected emitter to send either payloads or
Messages.The name of the channel (given in the
Channel annotation) indicates which channel is fed. It must match the name used in a method using@Incomingor an outgoing channel configured in the application configuration.The
OnOverflow annotationcan be used to configure what to do if messages are sent using the `MutinyEmitter` when a downstream subscriber hasn't requested more messages.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcomplete()Sends the completion event to the channel indicating that no other events will be sent afterward.voiderror(Exception e)Sends a failure event to the channel.booleanhasRequests()booleanisCancelled()<M extends Message<? extends T>>
voidsend(M msg)Sends a message to the channel.io.smallrye.mutiny.Uni<Void>send(T payload)Sends a payload to the channel.voidsendAndAwait(T payload)Sends a payload to the channel.io.smallrye.mutiny.subscription.CancellablesendAndForget(T payload)Sends a payload to the channel without waiting for acknowledgement.
-
-
-
Method Detail
-
send
io.smallrye.mutiny.Uni<Void> send(T payload)
Sends a payload to the channel.A
Messageobject will be created to hold the payload and the returnedUnican be subscribed to for triggering the send. When subscribed, anullitem will be passed to theUniwhen theMessageis acknowledged. If theMessageis never acknowledged, then theUniwill never be completed.The
Messagewill not be sent to the channel until theUnihas been subscribed to:emitter.send("a").subscribe().with(x -> { });- Parameters:
payload- the thing to send, must not benull- Returns:
- the
Uni, that requires subscription to send theMessage. - Throws:
IllegalStateException- if the channel has been cancelled or terminated or if an overflow strategy ofTHROW_EXCEPTIONorBUFFERis configured and the emitter overflows.
-
sendAndAwait
void sendAndAwait(T payload)
Sends a payload to the channel.A
Messageobject will be created to hold the payload.Execution will block waiting for the resulting
Messageto be acknowledged before returning.- Parameters:
payload- the thing to send, must not benull- Throws:
IllegalStateException- if the channel has been cancelled or terminated or if an overflow strategy ofTHROW_EXCEPTIONorBUFFERis configured and the emitter overflows.
-
sendAndForget
io.smallrye.mutiny.subscription.Cancellable sendAndForget(T payload)
Sends a payload to the channel without waiting for acknowledgement.A
Messageobject will be created to hold the payload.- Parameters:
payload- the thing to send, must not benull- Returns:
- the
Cancellablefrom the subscribedUni. - Throws:
IllegalStateException- if the channel has been cancelled or terminated or if an overflow strategy ofTHROW_EXCEPTIONorBUFFERis configured and the emitter overflows.
-
send
<M extends Message<? extends T>> void send(M msg)
Sends a message to the channel.- Type Parameters:
M- the Message type- Parameters:
msg- the Message to send, must not benull- Throws:
IllegalStateException- if the channel has been cancelled or terminated or if an overflow strategy ofTHROW_EXCEPTIONorBUFFERis configured and the emitter overflows.
-
complete
void complete()
Sends the completion event to the channel indicating that no other events will be sent afterward.
-
error
void error(Exception e)
Sends a failure event to the channel. No more events will be sent afterward.- Parameters:
e- the exception, must not benull
-
isCancelled
boolean isCancelled()
- Returns:
trueif the emitter has been terminated or the subscription cancelled.
-
hasRequests
boolean hasRequests()
- Returns:
trueif one or more subscribers request messages from the corresponding channel where the emitter connects to, returnfalseotherwise.
-
-