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
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classOne message as polled, with whatever the broker needs to acknowledge it. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final RetryPolicyThe retry policy of every subscription. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPollingTransport(RetryPolicy retry) A transport retrying byretry. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidack(String destination, String group, PollingTransport.Delivery delivery) Acknowledges a handled delivery.protected voiddeadLetter(String destination, String group, PollingTransport.Delivery delivery, String error) Sendsdeliveryto the dead-letter destination and acknowledges it.protected static Messageidentified(Message message, String id) message, given the identifier the broker knows it by.protected static booleanWhethermessagecarries a retry time still in the future.protected abstract List<PollingTransport.Delivery> Up tomaxmessages ofdestinationforgroup, waiting up towaitMillisfor the first; an empty list when none came.protected voidredeliver(String destination, String group, PollingTransport.Delivery delivery, int attempt, long notBefore) Hasdeliverydelivered again, asattempt, no sooner thannotBefore.protected voidStops every subscription, waiting for the messages being handled.subscribe(String destination, String group, int concurrency, MessageHandler handler) Startsconcurrencyconsumers ofdestinationingroup.Methods inherited from class MessageTransport
close, getName, isHealthy, isTransactional, send
-
Field Details
-
retry
The retry policy of every subscription.
-
-
Constructor Details
-
PollingTransport
A transport retrying byretry.
-
-
Method Details
-
poll
protected abstract List<PollingTransport.Delivery> poll(String destination, String group, int max, long waitMillis) throws IOException Up tomaxmessages ofdestinationforgroup, waiting up towaitMillisfor 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 Hasdeliverydelivered again, asattempt, no sooner thannotBefore. 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 withnotYet(Message, long).- Throws:
IOException
-
deadLetter
protected void deadLetter(String destination, String group, PollingTransport.Delivery delivery, String error) throws IOException Sendsdeliveryto the dead-letter destination and acknowledges it.- Throws:
IOException
-
identified
-
notYet
Whethermessagecarries 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:MessageTransportStarts
concurrencyconsumers ofdestinationingroup.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). Onmemory:anddb:a destination is a queue and every subscription competes for it.
- Specified by:
subscribein classMessageTransport- Throws:
IOException
-
stopSubscriptions
protected void stopSubscriptions()Stops every subscription, waiting for the messages being handled.
-