Class AmqpTransport
- All Implemented Interfaces:
Closeable, AutoCloseable
Messaging over RabbitMQ, or any AMQP 0-9-1 broker, with no client library.
cn1.messaging.url=amqp://app:secret@rabbit:5672/%2F
A destination is a durable queue of that name, declared on first use and
published to through the default exchange, persistent and with publisher
confirms: send(Message) returns once the broker has the message. Every listener
of a queue competes for its messages, whatever its group says -- a fan-out
to several groups is an exchange the application binds itself.
A subscription is one connection consuming with a prefetch equal to its
concurrency, so the broker holds back what no consumer thread is free to
take; one reader thread receives deliveries and the consumer threads
acknowledge each after its handler returns. A message whose handler failed
waits in <queue>.retry.<millis>, a queue whose time to live dead-letters it
back to the original, so a retry occupies no consumer while it waits. One
that fails every attempt goes to <queue>.dlq.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRegisters this transport withMessaging; the generated wiring does it.Nested classes/interfaces inherited from class PollingTransport
PollingTransport.Delivery -
Field Summary
Fields inherited from class PollingTransport
retry -
Constructor Summary
ConstructorsConstructorDescriptionAmqpTransport(String url, RetryPolicy retry, int timeoutMillis) A transport to the brokerurlnames; it connects on first use. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidack(String destination, String group, PollingTransport.Delivery delivery) Acknowledges a handled delivery.voidclose()Stops every subscription and closes the connection.getName()The scheme this transport was opened for:memory,db,redis,amqp,kafka.booleanWhether the broker answers, for the health endpoint.protected 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.voidSendsmessage.subscribe(String destination, String group, int concurrency, MessageHandler handler) Startsconcurrencyconsumers ofdestinationingroup.Methods inherited from class PollingTransport
deadLetter, identified, notYet, stopSubscriptionsMethods inherited from class MessageTransport
isTransactional
-
Constructor Details
-
AmqpTransport
A transport to the brokerurlnames; it connects on first use.
-
-
Method Details
-
getName
Description copied from class:MessageTransportThe scheme this transport was opened for:memory,db,redis,amqp,kafka.- Specified by:
getNamein classMessageTransport
-
send
Description copied from class:MessageTransportSendsmessage. With a database transport inside a transaction the message is written in that transaction and is seen only if it commits.- Specified by:
sendin classMessageTransport- Throws:
IOException
-
redeliver
protected void redeliver(String destination, String group, PollingTransport.Delivery delivery, int attempt, long notBefore) throws IOException Description copied from class:PollingTransportHasdeliverydelivered 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 withPollingTransport.notYet(Message, long).- Overrides:
redeliverin classPollingTransport- Throws:
IOException
-
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.
- Overrides:
subscribein classPollingTransport- Throws:
IOException
-
poll
protected List<PollingTransport.Delivery> poll(String destination, String group, int max, long waitMillis) throws IOException Description copied from class:PollingTransportUp tomaxmessages ofdestinationforgroup, waiting up towaitMillisfor the first; an empty list when none came.- Specified by:
pollin classPollingTransport- Throws:
IOException
-
ack
protected void ack(String destination, String group, PollingTransport.Delivery delivery) throws IOException Description copied from class:PollingTransportAcknowledges a handled delivery.- Specified by:
ackin classPollingTransport- Throws:
IOException
-
isHealthy
public boolean isHealthy()Description copied from class:MessageTransportWhether the broker answers, for the health endpoint. Never throws.- Overrides:
isHealthyin classMessageTransport
-
close
public void close()Description copied from class:MessageTransportStops every subscription and closes the connection. Never throws.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classMessageTransport
-