CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-amazonaws--aws-java-sdk-sqs

The AWS Java SDK for Amazon SQS module provides client classes for communicating with Amazon Simple Queue Service

Pending
Overview
Eval results
Files

client-management.mddocs/

Client Management

Client management capabilities provide the foundation for connecting to and configuring Amazon SQS services. This includes client creation, configuration, authentication setup, and lifecycle management.

Client Creation

Standard Client Builder

Create synchronous SQS clients with fluent configuration.

class AmazonSQSClientBuilder extends AwsSyncClientBuilder<AmazonSQSClientBuilder, AmazonSQS> {
    static AmazonSQSClientBuilder standard();
    static AmazonSQS defaultClient();
    AmazonSQS build();
}

Usage Example:

// Using default configuration
AmazonSQS client = AmazonSQSClientBuilder.defaultClient();

// Custom configuration
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withRegion(Regions.US_WEST_2)
    .withCredentials(new ProfileCredentialsProvider())
    .build();

Async Client Builder

Create asynchronous SQS clients for non-blocking operations.

class AmazonSQSAsyncClientBuilder extends AwsAsyncClientBuilder<AmazonSQSAsyncClientBuilder, AmazonSQSAsync> {
    static AmazonSQSAsyncClientBuilder standard();
    static AmazonSQSAsync defaultClient();
    AmazonSQSAsync build();
}

Usage Example:

// Default async client
AmazonSQSAsync asyncClient = AmazonSQSAsyncClientBuilder.defaultClient();

// Custom async client
AmazonSQSAsync asyncClient = AmazonSQSAsyncClientBuilder.standard()
    .withRegion(Regions.EU_WEST_1)
    .withExecutorFactory(() -> Executors.newFixedThreadPool(10))
    .build();

Client Interfaces

Synchronous Client Interface

Main interface for synchronous SQS operations.

interface AmazonSQS {
    String ENDPOINT_PREFIX = "sqs";
    
    // Endpoint configuration (deprecated - use builders instead)
    void setEndpoint(String endpoint);
    void setRegion(Region region);
    
    // Client lifecycle
    void shutdown();
    ResponseMetadata getCachedResponseMetadata(AmazonWebServiceRequest request);
    
    // All SQS operations...
    CreateQueueResult createQueue(CreateQueueRequest request);
    SendMessageResult sendMessage(SendMessageRequest request);
    ReceiveMessageResult receiveMessage(ReceiveMessageRequest request);
    // ... (full operation list in respective capability docs)
}

Asynchronous Client Interface

Interface extending synchronous operations with Future-based async methods.

interface AmazonSQSAsync extends AmazonSQS {
    // All sync methods plus async variants with Future return types
    Future<CreateQueueResult> createQueueAsync(CreateQueueRequest request);
    Future<CreateQueueResult> createQueueAsync(CreateQueueRequest request,
        AsyncHandler<CreateQueueRequest, CreateQueueResult> asyncHandler);
    
    Future<SendMessageResult> sendMessageAsync(SendMessageRequest request);
    Future<SendMessageResult> sendMessageAsync(SendMessageRequest request,
        AsyncHandler<SendMessageRequest, SendMessageResult> asyncHandler);
    
    // ... async variants for all operations
}

Client Implementations

Standard Synchronous Client

Thread-safe implementation of the synchronous SQS interface.

class AmazonSQSClient implements AmazonSQS {
    // Constructors (prefer using builders)
    AmazonSQSClient();
    AmazonSQSClient(AWSCredentials awsCredentials);
    AmazonSQSClient(AWSCredentialsProvider awsCredentialsProvider);
    AmazonSQSClient(ClientConfiguration clientConfiguration);
    // Additional constructor overloads...
}

Standard Asynchronous Client

Thread-safe implementation of the asynchronous SQS interface.

class AmazonSQSAsyncClient extends AmazonSQSClient implements AmazonSQSAsync {
    // Constructors (prefer using builders)
    AmazonSQSAsyncClient();
    AmazonSQSAsyncClient(AWSCredentials awsCredentials);
    AmazonSQSAsyncClient(AWSCredentialsProvider awsCredentialsProvider);
    // Additional constructor overloads...
}

Client Configuration

Authentication

Configure AWS credentials for API access:

// Using default credential chain
AmazonSQS client = AmazonSQSClientBuilder.defaultClient();

// Using specific credential provider
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withCredentials(new ProfileCredentialsProvider("myprofile"))
    .build();

// Using access keys (not recommended for production)
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withCredentials(new AWSStaticCredentialsProvider(
        new BasicAWSCredentials("accessKey", "secretKey")))
    .build();

Region Configuration

Set the AWS region for SQS operations:

// Specific region
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withRegion(Regions.US_EAST_1)
    .build();

// Region from string
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withRegion("us-west-2")
    .build();

// Custom endpoint (for testing or special configurations)
AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withEndpointConfiguration(new EndpointConfiguration(
        "https://sqs.us-west-2.amazonaws.com", "us-west-2"))
    .build();

HTTP Configuration

Customize HTTP client settings:

ClientConfiguration config = new ClientConfiguration()
    .withConnectionTimeout(5000)
    .withSocketTimeout(10000)
    .withMaxConnections(50)
    .withRetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_POLICY);

AmazonSQS client = AmazonSQSClientBuilder.standard()
    .withClientConfiguration(config)
    .build();

Client Lifecycle

Shutdown

Properly close clients to release resources:

// Synchronous shutdown
client.shutdown();

// For async clients, also shutdown executor if custom
if (asyncClient instanceof AmazonSQSAsyncClient) {
    asyncClient.shutdown();
}

Response Metadata

Access diagnostic information about requests:

SendMessageRequest request = new SendMessageRequest()
    .withQueueUrl(queueUrl)
    .withMessageBody("test message");

SendMessageResult result = client.sendMessage(request);

// Get response metadata
ResponseMetadata metadata = client.getCachedResponseMetadata(request);
String requestId = metadata.getRequestId();
Map<String, String> responseHeaders = metadata.getHttpHeaders();

Error Handling

Common client-level exceptions and handling:

try {
    AmazonSQS client = AmazonSQSClientBuilder.standard()
        .withRegion("invalid-region")
        .build();
} catch (AmazonClientException e) {
    // Client configuration or network errors
    System.err.println("Client error: " + e.getMessage());
} catch (AmazonServiceException e) {
    // Service-side errors
    System.err.println("Service error: " + e.getErrorCode() + " - " + e.getMessage());
}

Thread Safety

All SQS client implementations are thread-safe and can be shared across multiple threads:

// Single client instance can be used by multiple threads
AmazonSQS sharedClient = AmazonSQSClientBuilder.defaultClient();

// Use in multiple threads safely
Runnable task = () -> {
    try {
        ReceiveMessageResult result = sharedClient.receiveMessage(
            new ReceiveMessageRequest(queueUrl));
        // Process messages...
    } catch (Exception e) {
        // Handle per-thread errors
    }
};

// Submit to thread pool
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
    executor.submit(task);
}

Install with Tessl CLI

npx tessl i tessl/maven-com-amazonaws--aws-java-sdk-sqs

docs

async-operations.md

buffered-client.md

client-management.md

dead-letter-queues.md

index.md

message-operations.md

message-visibility.md

queue-operations.md

queue-permissions.md

queue-tagging.md

tile.json