Class SqsTransport
- All Implemented Interfaces:
Closeable, AutoCloseable
Messaging over Amazon SQS, signed with the backend's own SigV4 signer and no AWS SDK.
cn1.messaging.url=sqs://eu-west-1
The host part is a region, which addresses
sqs.<region>.amazonaws.com, or a host:port endpoint for a compatible
service (ElasticMQ, LocalStack), whose region comes from
cn1.messaging.sqs.region (default us-east-1). Only an endpoint on
loopback is spoken to over plain HTTP. Credentials are resolved the way
Credentials.resolve() documents: the environment, then the container,
then the instance metadata service.
A destination is a standard queue, created on first use. SQS allows
letters, digits, - and _ in a queue name, so every other character of
a destination -- the . of orders.dlq -- becomes -. Listeners of one
queue compete for its messages whatever their group: SQS has no consumer
groups, and fan-out is SNS's job.
The body is sent base64 encoded, so any payload survives; the key and
headers travel in one message attribute, cn1-headers, which keeps clear of
SQS's limit of ten attributes. A message from a producer that is not this
transport is read as it is: its body as UTF-8 text and its string
attributes as headers. SQS limits a message to 256 KiB, which the encoding
makes about 190 KiB of payload.
A message is handed to one consumer for cn1.messaging.lease milliseconds
(SQS's visibility timeout); one not settled in that time is delivered
again. A failed message is not copied: its visibility is pushed back by the
retry delay, and SQS's own receive count is its attempt number. A delay is
at most twelve hours, SQS's limit.
-
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
ConstructorsConstructorDescriptionSqsTransport(String url, String region, RetryPolicy retry, int leaseMillis) A transport to the region or endpointurlnames;regionsigns requests to an endpoint, and may be null forus-east-1. -
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) Keeps the message where it is, hidden untilnotBefore: SQS counts the next receive as the next attempt.voidSendsmessage.Methods inherited from class PollingTransport
deadLetter, identified, notYet, stopSubscriptions, subscribeMethods inherited from class MessageTransport
isTransactional
-
Constructor Details
-
SqsTransport
public SqsTransport(String url, String region, RetryPolicy retry, int leaseMillis) throws IOException A transport to the region or endpointurlnames;regionsigns requests to an endpoint, and may be null forus-east-1.- Throws:
IOException
-
-
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
-
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
-
redeliver
protected void redeliver(String destination, String group, PollingTransport.Delivery delivery, int attempt, long notBefore) throws IOException Keeps the message where it is, hidden untilnotBefore: SQS counts the next receive as the next attempt.- Overrides:
redeliverin 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
-