Class AloSqsSender<T>

  • Type Parameters:
    T - The un-serialized type of SQS Message bodies
    All Implemented Interfaces:
    Closeable, AutoCloseable

    public class AloSqsSender<T>
    extends Object
    implements Closeable
    A reactive sender of Alo data to SQS queues, with forwarding methods for non-Alo items.

    At most one instance of a SqsSender is kept and can be closed upon invoking close(). However, if after closing, more sent Publishers are subscribed to, a new Sender instance will be created and cached.

    • Field Detail

      • CONFIG_PREFIX

        public static final String CONFIG_PREFIX
        Prefix used on all AloSqsSender-specific configurations.
        See Also:
        Constant Field Values
      • BATCH_SIZE_CONFIG

        public static final String BATCH_SIZE_CONFIG
        The max number of Messages to send in each SQS batch send request. Defaults to 1, meaning batching is disabled and each Message is sent in its own request. When batching is enabled (batch size > 1), BATCH_DURATION_CONFIG must also be configured such that there is an upper bound on how long a batch will remain open when waiting for it to be filled.
        See Also:
        Constant Field Values
      • BATCH_DURATION_CONFIG

        public static final String BATCH_DURATION_CONFIG
        When batching is enabled, this configures the maximum amount of time a batch will remain open while waiting for it to be filled. Specified as an ISO-8601 Duration, e.g. PT0.1S
        See Also:
        Constant Field Values
      • BATCH_PREFETCH_CONFIG

        public static final String BATCH_PREFETCH_CONFIG
        The number of batches to prefetch for sending. Note that the resulting upstream prefetch will be the product of batch size and batch prefetch.
        See Also:
        Constant Field Values
      • MAX_REQUESTS_IN_FLIGHT_CONFIG

        public static final String MAX_REQUESTS_IN_FLIGHT_CONFIG
        Configures the maximum number of SQS Requests in flight per sent Publisher. When batching is disabled, this equates to the maximum number of Messages concurrently being sent. When batching is enabled, this equates to the maximum number batches concurrently being sent.
        See Also:
        Constant Field Values
    • Method Detail

      • create

        public static <T> AloSqsSender<T> create​(SqsConfigSource configSource)
        Creates a new AloSqsSender from the provided SqsConfigSource
        Type Parameters:
        T - The type of messages bodies sent by this sender
        Parameters:
        configSource - The reactive source of SqsConfig
        Returns:
        A new AloSqsSender
      • sendBodies

        public Flux<SqsSenderResult<T>> sendBodies​(org.reactivestreams.Publisher<T> bodies,
                                                   SqsMessageCreator<T> messageCreator,
                                                   String queueUrl)
        Sends a sequence of message bodies to be populated in SqsMessages to the specified queue URL.

        The output of each sent message body is an SqsSenderResult containing the sent value.

        Parameters:
        bodies - A Publisher of SQS message bodies
        messageCreator - A factory that creates SqsMessages from message bodies
        queueUrl - URL of the queue to send messages to
        Returns:
        a Publisher of the results of each sent message
      • sendMessage

        public Mono<SqsSenderResult<SqsMessage<T>>> sendMessage​(SqsMessage<T> message,
                                                                String queueUrl)
        Send a single SqsMessage
        Parameters:
        message - A message to send
        queueUrl - URL of the queue to send the message to
        Returns:
        A Publisher of the result of sending the message
      • sendMessages

        public Flux<SqsSenderResult<SqsMessage<T>>> sendMessages​(org.reactivestreams.Publisher<SqsMessage<T>> messages,
                                                                 String queueUrl)
        Sends a sequence of SqsMessages

        The output of each sent message is an SqsSenderResult containing the sent message.

        Parameters:
        messages - A Publisher of messages to send
        queueUrl - URL of the queue to send messages to
        Returns:
        A Publisher of items referencing the result of each sent message
      • sendAloBodies

        public Function<org.reactivestreams.Publisher<io.atleon.core.Alo<T>>,​io.atleon.core.AloFlux<SqsSenderResult<T>>> sendAloBodies​(SqsMessageCreator<T> messageCreator,
                                                                                                                                             String queueUrl)
        Creates a Function that can be used to transform a Publisher of Alo items referencing SQS message bodies to a Publisher of Alo items referencing the result of sending each message body. See sendAloBodies(Publisher, SqsMessageCreator, String) for further information.
        Parameters:
        messageCreator - A factory that creates SqsMessages from message bodies
        queueUrl - URL of the queue to send messages to
        Returns:
        A Function useful for Publisher transformations
      • sendAloBodies

        public io.atleon.core.AloFlux<SqsSenderResult<T>> sendAloBodies​(org.reactivestreams.Publisher<io.atleon.core.Alo<T>> aloBodies,
                                                                        SqsMessageCreator<T> messageCreator,
                                                                        String queueUrl)
        Sends a sequence of Alo items referencing message bodies to be populated in SqsMessages to the specified queue URL.

        The output of each sent message body is an SqsSenderResult containing the sent value. Each emitted item is an Alo item referencing an SqsSenderResult and must be acknowledged or nacknowledged such that its processing can be marked complete at the origin of the message.

        Parameters:
        aloBodies - A Publisher of Alo items referencing SQS message bodies
        messageCreator - A factory that creates SqsMessages from message bodies
        queueUrl - URL of the queue to send messages to
        Returns:
        a Publisher of Alo items referencing the result of each sent message
      • sendAloMessages

        public Function<org.reactivestreams.Publisher<io.atleon.core.Alo<SqsMessage<T>>>,​io.atleon.core.AloFlux<SqsSenderResult<SqsMessage<T>>>> sendAloMessages​(String queueUrl)
        Creates a Function that can be used to transform a Publisher of Alo items referencing SQS messages to a Publisher of Alo items referencing the result of sending each message. See sendAloMessages(Publisher, String) for further information.
        Parameters:
        queueUrl - URL of the queue to send messages to
        Returns:
        A Function useful for Publisher transformations
      • sendAloMessages

        public io.atleon.core.AloFlux<SqsSenderResult<SqsMessage<T>>> sendAloMessages​(org.reactivestreams.Publisher<io.atleon.core.Alo<SqsMessage<T>>> aloMessages,
                                                                                      String queueUrl)
        Sends a sequence of Alo items referencing SqsMessages

        The output of each sent message is an SqsSenderResult containing the sent message. Each emitted item is an Alo item referencing a SqsSenderResult and must be acknowledged or nacknowledged such that its processing can be marked complete at the origin of the message.

        Parameters:
        aloMessages - A Publisher of Alo items referencing messages to send
        queueUrl - URL of the queue to send messages to
        Returns:
        A Publisher of Alo items referencing the result of each sent message
      • close

        public void close​(Object reason)
        Closes this sender and logs the provided reason.
        Parameters:
        reason - The reason this sender is being closed