Class MessageTransport

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

public abstract class MessageTransport extends Object implements Closeable

A broker connection: what sends messages and runs subscriptions. One per server, opened by Messaging.current() from the configuration; application code sends through MessageTemplate and receives through @MessageListener methods rather than calling this directly.

Delivery is at least once. A handler that returns acknowledges its message; one that throws has it delivered again after a backoff, and after cn1.messaging.retry.max-attempts deliveries it goes to the destination's dead-letter destination, <destination>.dlq, with the failure in its Message.ERROR header.

  • Constructor Details

    • MessageTransport

      public MessageTransport()
  • Method Details

    • getName

      public abstract String getName()
      The scheme this transport was opened for: memory, db, redis, amqp, kafka.
    • send

      public abstract void send(Message message) throws IOException
      Sends message. With a database transport inside a transaction the message is written in that transaction and is seen only if it commits.
      Throws:
      IOException
    • subscribe

      public abstract Subscription subscribe(String destination, String group, int concurrency, MessageHandler handler) throws IOException

      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.
      Throws:
      IOException
    • isTransactional

      public boolean isTransactional()
      Whether a send is part of the calling thread's database transaction by itself, so it needs no outbox.
    • isHealthy

      public boolean isHealthy()
      Whether the broker answers, for the health endpoint. Never throws.
    • close

      public abstract void close()
      Stops every subscription and closes the connection. Never throws.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable