44
55The library provides an asynchronous, batched messaging client for Amazon SNS, supporting both AWS SDK v1 and v2. It is organized as a multi-module Maven project:
66
7- | Module | Artifact | Purpose |
8- | ---| ---| ---|
9- | ` amazon-sns-java-messaging-lib-template ` | * (internal)* | SDK-agnostic core: batching, queuing, threading, metrics |
10- | ` amazon-sns-java-messaging-lib-v1 ` | ` amazon-sns-java-messaging-lib-v1 ` | AWS SDK v1 implementation (` AmazonSNS ` client) |
11- | ` amazon-sns-java-messaging-lib-v2 ` | ` amazon-sns-java-messaging-lib-v2 ` | AWS SDK v2 implementation (` SnsClient ` ) |
7+ | Module | Artifact | Purpose |
8+ | ------------------------------------------ | ------------------------------------ | ------------------------------------------------------- ---|
9+ | ` amazon-sns-java-messaging-lib-template ` | * (internal)* | SDK-agnostic core: batching, queuing, threading, metrics |
10+ | ` amazon-sns-java-messaging-lib-v1 ` | ` amazon-sns-java-messaging-lib-v1 ` | AWS SDK v1 implementation (` AmazonSNS ` client) |
11+ | ` amazon-sns-java-messaging-lib-v2 ` | ` amazon-sns-java-messaging-lib-v2 ` | AWS SDK v2 implementation (` SnsClient ` ) |
1212
1313### Core Components
1414
15- ```
16- ┌──────────────────────────────────────────────────────────┐
15+ ``` text
16+ ┌──────────────────────────────────────────────────────────── ┐
1717│ AmazonSnsTemplate<E> │
18- ├──────────────────────────────────────────────────────────┤
19- │ ┌──────────────────────┐ ┌────────────────────────┐ │
18+ ├──────────────────────────────────────────────────────────── ┤
19+ │ ┌─────────────────────── ┐ ┌─ ────────────────────────┐ │
2020│ │ AmazonSnsProducer<E> │ │ AmazonSnsConsumer<R,O> │ │
21- │ │ (AbstractProducer) │ │ (AbstractConsumer) │ │
22- │ │ │ │ │ │
23- │ │ - BlockingQueue │ │ - ScheduledExecutor │ │
24- │ │ - PendingRequests │ │ - Batching Logic │ │
25- │ └──────────┬───────────┘ └───────────┬────────────┘ │
26- │ │ │ │
27- │ send(E) publishBatch(...) │
28- └─────────────┼────────────────────────────┼ ───────────────┘
29- │ │
30- ▼ ▼
31- ┌──────────────────────────────────────────┐
21+ │ │ (AbstractProducer) │ │ (AbstractConsumer) │ │
22+ │ │ │ │ │ │
23+ │ │ - BlockingQueue │ │ - ScheduledExecutor │ │
24+ │ │ - PendingRequests │ │ - Batching Logic │ │
25+ │ └──────────┬──────────── ┘ └───────────┬─ ────────────┘ │
26+ │ │ │ │
27+ │ send(E) publishBatch(...) │
28+ └─────────────┼─────────────────────────────┼─ ───────────────┘
29+ │ │
30+ ▼ ▼
31+ ┌─────────────────────────────────────────── ┐
3232 │ Amazon SNS (v1/v2) │
33- └──────────────────────────────────────────┘
33+ └─────────────────────────────────────────── ┘
3434```
3535
3636- ** ` AmazonSnsTemplate ` ** — Main entry point. Created via a fluent builder (` AmazonSnsTemplate.builder(snsClient, topicProperty) ` ).
@@ -115,13 +115,13 @@ For **FIFO** topics, messages are published **synchronously** on a single-thread
115115
116116### TopicProperty
117117
118- | Property | Type | Default | Description |
119- | ---| ---| ---| ---|
120- | ` fifo ` | ` boolean ` | ` false ` | Whether the SNS topic is FIFO |
121- | ` topicArn ` | ` String ` | — | The SNS topic ARN |
122- | ` maximumPoolSize ` | ` int ` | — | Max threads for the producer pool |
123- | ` maxBatchSize ` | ` int ` | — | Max messages per batch request |
124- | ` linger ` | ` long ` (ms) | — | Time to wait before flushing a batch |
118+ | Property | Type | Default | Description |
119+ | ------------------- | ------------- | --------- | ----------------------------------- ---|
120+ | ` fifo ` | ` boolean ` | ` false ` | Whether the SNS topic is FIFO |
121+ | ` topicArn ` | ` String ` | — | The SNS topic ARN |
122+ | ` maximumPoolSize ` | ` int ` | — | Max threads for the producer pool |
123+ | ` maxBatchSize ` | ` int ` | — | Max messages per batch request |
124+ | ` linger ` | ` long ` (ms) | — | Time to wait before flushing a batch |
125125
126126** Note** : The in-memory buffer size = ` maximumPoolSize × maxBatchSize ` . Large values consume proportionally more memory.
127127
@@ -210,41 +210,41 @@ The library integrates with Micrometer and records the following metrics when a
210210
211211Tags: ` topic ` = ` <topicArn> `
212212
213- | Metric Name | Type | Description | Config |
214- | ---| ---| ---| ---|
215- | ` sns.publish.attempts ` | ` Counter ` | Total number of SNS PublishBatch calls attempted | — |
216- | ` sns.publish.success ` | ` Counter ` | Individual SNS messages acknowledged as successful | — |
217- | ` sns.publish.failure ` | ` Counter ` | Individual SNS messages that failed | Dynamic tags: ` error_code ` , ` error_type ` |
218- | ` sns.publish.duration ` | ` Timer ` | End-to-end latency of SNS PublishBatch calls | Percentiles: 0.5, 0.95, 0.99 |
219- | ` sns.publish.batch.size ` | ` DistributionSummary ` | Number of entries per SNS PublishBatch request | — |
220- | ` sns.publish.inflight ` | ` Gauge ` | PublishBatches currently in progress | Backed by ` AtomicInteger ` |
213+ | Metric Name | Type | Description | Config |
214+ | -------------------------- | ----------------------- | ---------------------------------------------------- | --------------------------------------- ---|
215+ | ` sns.publish.attempts ` | ` Counter ` | Total number of SNS PublishBatch calls attempted | — |
216+ | ` sns.publish.success ` | ` Counter ` | Individual SNS messages acknowledged as successful | — |
217+ | ` sns.publish.failure ` | ` Counter ` | Individual SNS messages that failed | Dynamic tags: ` error_code ` , ` error_type ` |
218+ | ` sns.publish.duration ` | ` Timer ` | End-to-end latency of SNS PublishBatch calls | Percentiles: 0.5, 0.95, 0.99 |
219+ | ` sns.publish.batch.size ` | ` DistributionSummary ` | Number of entries per SNS PublishBatch request | — |
220+ | ` sns.publish.inflight ` | ` Gauge ` | PublishBatches currently in progress | Backed by ` AtomicInteger ` |
221221
222222The ` sns.publish.failure ` counter is created dynamically with additional ` error_code ` (AWS error code string) and ` error_type ` (amazon_service_exception or unknown) tags.
223223
224224### Blocking Queue Metrics
225225
226226Tags: ` name ` = ` <queueName> `
227227
228- | Metric Name | Type | Description | Config |
229- | ---| ---| ---| ---|
230- | ` blocking.queue.puts.total ` | ` Counter ` | Total number of successful put operations | — |
231- | ` blocking.queue.puts.failed ` | ` Counter ` | Total number of put operations that threw an exception | — |
232- | ` blocking.queue.put.duration ` | ` Timer ` | Latency of put operations (including wait time when queue is full) | Percentile histogram |
233- | ` blocking.queue.takes.total ` | ` Counter ` | Total number of successful take operations | — |
234- | ` blocking.queue.takes.failed ` | ` Counter ` | Total number of take operations that threw an exception | — |
235- | ` blocking.queue.take.duration ` | ` Timer ` | Latency of take operations (including wait time when queue is empty) | Percentile histogram |
236- | ` blocking.queue.size ` | ` Gauge ` | Current number of elements in the queue | Calls ` delegate.size() ` |
228+ | Metric Name | Type | Description | Config |
229+ | -------------------------------- | ----------- | ---------------------------------------------------------------------- | ---------------------- ---|
230+ | ` blocking.queue.puts.total ` | ` Counter ` | Total number of successful put operations | — |
231+ | ` blocking.queue.puts.failed ` | ` Counter ` | Total number of put operations that threw an exception | — |
232+ | ` blocking.queue.put.duration ` | ` Timer ` | Latency of put operations (including wait time when queue is full) | Percentile histogram |
233+ | ` blocking.queue.takes.total ` | ` Counter ` | Total number of successful take operations | — |
234+ | ` blocking.queue.takes.failed ` | ` Counter ` | Total number of take operations that threw an exception | — |
235+ | ` blocking.queue.take.duration ` | ` Timer ` | Latency of take operations (including wait time when queue is empty) | Percentile histogram |
236+ | ` blocking.queue.size ` | ` Gauge ` | Current number of elements in the queue | Calls ` delegate.size() ` |
237237
238238### Executor Metrics
239239
240240Tags: ` name ` = ` <executorName> `
241241
242- | Metric Name | Type | Description | Config |
243- | ---| ---| ---| ---|
244- | ` executor.active ` | ` Gauge ` | Number of tasks currently being executed by pool threads | Backed by ` AtomicInteger ` |
245- | ` executor.tasks.succeeded ` | ` Counter ` | Total number of tasks that completed without throwing an exception | — |
246- | ` executor.tasks.failed ` | ` Counter ` | Total number of tasks that completed by throwing an exception | — |
247- | ` executor.task.duration ` | ` Timer ` | Wall-clock duration of each task execution | — |
242+ | Metric Name | Type | Description | Config |
243+ | ---------------------------- | ----------- | -------------------------------------------------------------------- | ------------------------ ---|
244+ | ` executor.active ` | ` Gauge ` | Number of tasks currently being executed by pool threads | Backed by ` AtomicInteger ` |
245+ | ` executor.tasks.succeeded ` | ` Counter ` | Total number of tasks that completed without throwing an exception | — |
246+ | ` executor.tasks.failed ` | ` Counter ` | Total number of tasks that completed by throwing an exception | — |
247+ | ` executor.task.duration ` | ` Timer ` | Wall-clock duration of each task execution | — |
248248
249249---
250250
@@ -258,13 +258,14 @@ Tags: `name` = `<executorName>`
258258
259259## Exception Handling
260260
261- | Exception | Condition |
262- | ---| ---|
263- | ` MaximumAllowedMessageException ` | A single message exceeds the 256KB SNS payload limit |
264- | SDK exceptions (` AmazonServiceException ` / ` AwsServiceException ` ) | Service-side errors during ` publishBatch ` |
265- | SDK exceptions (` AmazonClientException ` / ` AwsClientException ` ) | Client-side errors (network, serialization) |
261+ | Exception | Condition |
262+ | ------------------------------------------------------------------- | --------------------------------------------------- ---|
263+ | ` MaximumAllowedMessageException ` | A single message exceeds the 256KB SNS payload limit |
264+ | SDK exceptions (` AmazonServiceException ` / ` AwsServiceException ` ) | Service-side errors during ` publishBatch ` |
265+ | SDK exceptions (` AmazonClientException ` / ` AwsClientException ` ) | Client-side errors (network, serialization) |
266266
267267Failed messages are delivered to the failure callback with:
268+
268269- ` messageId ` — the original request ID
269270- ` code ` — the error code
270271- ` message ` — error description
0 commit comments