Interface ContextualEmitter<T>

Type Parameters:
T - the payload type
All Superinterfaces:
io.smallrye.reactive.messaging.EmitterType
All Known Implementing Classes:
ContextualEmitterImpl

public interface ContextualEmitter<T> extends io.smallrye.reactive.messaging.EmitterType
Emitter implementation that plays better with context propagation, especially with the request scoped context. The message emit of this emitter makes sure that

  • the message context is captured when active thread context plan is applied
  • the message is emitted only after the context propagation ends the context switch, destroying the intermediate state for cleared contexts.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sends the completion event to the channel indicating that no other events will be sent afterward.
    void
    Sends a failure event to the channel.
    boolean
     
    boolean
     
    io.smallrye.mutiny.Uni<Void>
    send(T payload)
    Sends a payload to the channel.
    void
    sendAndAwait(T payload)
    Sends a payload to the channel.
    io.smallrye.mutiny.subscription.Cancellable
    sendAndForget(T payload)
    Sends a payload to the channel without waiting for acknowledgement.
    <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>>
    io.smallrye.mutiny.Uni<Void>
    sendMessage(M msg)
    Sends a message to the channel.
    <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>>
    void
    Sends a message to the channel.
    <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>>
    io.smallrye.mutiny.subscription.Cancellable
    Sends a message to the channel without waiting for acknowledgement.
  • Method Details

    • send

      @CheckReturnValue io.smallrye.mutiny.Uni<Void> send(T payload)
      Sends a payload to the channel.

      A Message object will be created to hold the payload and the returned Uni can be subscribed to for triggering the send. When subscribed, a null item will be passed to the Uni when the Message is acknowledged. If the Message is never acknowledged, then the Uni will never be completed.

      The Message will not be sent to the channel until the Uni has been subscribed to:

       emitter.send("a").subscribe().with(x -> {
       });
       
      Parameters:
      payload - the thing to send, must not be null
      Returns:
      the Uni, that requires subscription to send the Message.
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is configured and the emitter overflows.
    • sendAndAwait

      void sendAndAwait(T payload)
      Sends a payload to the channel.

      A Message object will be created to hold the payload.

      Execution will block waiting for the resulting Message to be acknowledged before returning.

      Parameters:
      payload - the thing to send, must not be null
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is 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 Message object will be created to hold the payload.

      Parameters:
      payload - the thing to send, must not be null
      Returns:
      the Cancellable from the subscribed Uni.
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is configured and the emitter overflows.
    • sendMessage

      @CheckReturnValue <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>> io.smallrye.mutiny.Uni<Void> sendMessage(M msg)
      Sends a message to the channel.
      Type Parameters:
      M - the Message type
      Parameters:
      msg - the Message to send, must not be null
      Returns:
      the Uni, that requires subscription to send the Message.
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is configured and the emitter overflows.
    • sendMessageAndAwait

      <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>> void sendMessageAndAwait(M msg)
      Sends a message to the channel. Execution will block waiting for the resulting Message to be acknowledged before returning.
      Type Parameters:
      M - the Message type
      Parameters:
      msg - the Message to send, must not be null
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is configured and the emitter overflows.
    • sendMessageAndForget

      <M extends org.eclipse.microprofile.reactive.messaging.Message<? extends T>> io.smallrye.mutiny.subscription.Cancellable sendMessageAndForget(M msg)
      Sends a message to the channel without waiting for acknowledgement.
      Type Parameters:
      M - the Message type
      Parameters:
      msg - the Message to send, must not be null
      Returns:
      the Cancellable from the subscribed Uni.
      Throws:
      IllegalStateException - if the channel has been cancelled or terminated or if an overflow strategy of THROW_EXCEPTION or BUFFER is 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 be null
    • isCancelled

      boolean isCancelled()
      Returns:
      true if the emitter has been terminated or the subscription cancelled.
    • hasRequests

      boolean hasRequests()
      Returns:
      true if one or more subscribers request messages from the corresponding channel where the emitter connects to, return false otherwise.