Class PollingTransport

java.lang.Object
com.codename1.backend.messaging.MessageTransport
com.codename1.backend.messaging.PollingTransport
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
AmqpTransport, KafkaTransport, PubSubTransport, RedisStreamTransport, SqsTransport

public abstract class PollingTransport extends MessageTransport

A transport whose consumers ask the broker for messages in a loop: the database, Redis Streams, Kafka. It runs each subscription's consumer threads, and turns a handler's failure into a later delivery or a dead letter, so a subclass only says how to poll, acknowledge and reschedule.

Consumer threads run as part of the server that subscribed, so a handler reaches that server's beans, data source and key/value store.

  • Field Details

    • retry

      protected final RetryPolicy retry
      The retry policy of every subscription.
  • Constructor Details

    • PollingTransport

      protected PollingTransport(RetryPolicy retry)
      A transport retrying by retry.
  • Method Details

    • poll

      protected abstract List<PollingTransport.Delivery> poll(String destination, String group, int max, long waitMillis) throws IOException
      Up to max messages of destination for group, waiting up to waitMillis for the first; an empty list when none came.
      Throws:
      IOException
    • ack

      protected abstract void ack(String destination, String group, PollingTransport.Delivery delivery) throws IOException
      Acknowledges a handled delivery.
      Throws:
      IOException
    • redeliver

      protected void redeliver(String destination, String group, PollingTransport.Delivery delivery, int attempt, long notBefore) throws IOException
      Has delivery delivered again, as attempt, no sooner than notBefore. The default sends a copy carrying the attempt and the time in its headers and acknowledges the original; a consumer that polls the copy early puts it back with notYet(Message, long).
      Throws:
      IOException
    • deadLetter

      protected void deadLetter(String destination, String group, PollingTransport.Delivery delivery, String error) throws IOException
      Sends delivery to the dead-letter destination and acknowledges it.
      Throws:
      IOException
    • identified

      protected static Message identified(Message message, String id)
      message, given the identifier the broker knows it by.
    • notYet

      protected static boolean notYet(Message message, long now)
      Whether message carries a retry time still in the future.
    • subscribe

      public Subscription subscribe(String destination, String group, int concurrency, MessageHandler handler) throws IOException
      Description copied from class: MessageTransport

      Starts concurrency consumers of destination in group.

      • group: subscriptions of one group share the messages between them, and each group sees every message -- on a transport with groups (Redis Streams, Kafka, AMQP through one queue per group). On memory: and db: a destination is a queue and every subscription competes for it.
      Specified by:
      subscribe in class MessageTransport
      Throws:
      IOException
    • stopSubscriptions

      protected void stopSubscriptions()
      Stops every subscription, waiting for the messages being handled.