use of com.amazonaws.services.sqs.AmazonSQS in project camel by apache.
the class SqsEndpoint method createClient.
/**
* Provide the possibility to override this method for an mock implementation
* @return AmazonSQSClient
*/
AmazonSQS createClient() {
AmazonSQS client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonSQSClient(credentials, clientConfiguration);
} else {
client = new AmazonSQSClient(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonSQSClient();
} else {
client = new AmazonSQSClient(clientConfiguration);
}
}
return client;
}
use of com.amazonaws.services.sqs.AmazonSQS in project aws-doc-sdk-examples by awsdocs.
the class UsingQueues method main.
public static void main(String[] args) {
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// Creating a Queue
CreateQueueRequest create_request = new CreateQueueRequest(QUEUE_NAME).addAttributesEntry("DelaySeconds", "60").addAttributesEntry("MessageRetentionPeriod", "86400");
try {
sqs.createQueue(create_request);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
// Get the URL for a queue
String queue_url = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
// Delete the Queue
sqs.deleteQueue(queue_url);
sqs.createQueue("Queue1" + new Date().getTime());
sqs.createQueue("Queue2" + new Date().getTime());
sqs.createQueue("MyQueue" + new Date().getTime());
// List your queues
ListQueuesResult lq_result = sqs.listQueues();
System.out.println("Your SQS Queue URLs:");
for (String url : lq_result.getQueueUrls()) {
System.out.println(url);
}
// List queues with filters
String name_prefix = "Queue";
lq_result = sqs.listQueues(new ListQueuesRequest(name_prefix));
System.out.println("Queue URLs with prefix: " + name_prefix);
for (String url : lq_result.getQueueUrls()) {
System.out.println(url);
}
}
use of com.amazonaws.services.sqs.AmazonSQS in project aws-doc-sdk-examples by awsdocs.
the class VisibilityTimeout method changeMessageVisibilityMultiple.
// Change the visibility timeout for multiple messages.
public static void changeMessageVisibilityMultiple(String queue_url, int timeout) {
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
List<ChangeMessageVisibilityBatchRequestEntry> entries = new ArrayList<ChangeMessageVisibilityBatchRequestEntry>();
entries.add(new ChangeMessageVisibilityBatchRequestEntry("unique_id_msg1", sqs.receiveMessage(queue_url).getMessages().get(0).getReceiptHandle()).withVisibilityTimeout(timeout));
entries.add(new ChangeMessageVisibilityBatchRequestEntry("unique_id_msg2", sqs.receiveMessage(queue_url).getMessages().get(0).getReceiptHandle()).withVisibilityTimeout(timeout + 200));
sqs.changeMessageVisibilityBatch(queue_url, entries);
}
use of com.amazonaws.services.sqs.AmazonSQS in project aws-doc-sdk-examples by awsdocs.
the class VisibilityTimeout method changeMessageVisibilitySingle.
// Change the visibility timeout for a single message
public static void changeMessageVisibilitySingle(String queue_url, int timeout) {
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// Get the receipt handle for the first message in the queue.
String receipt = sqs.receiveMessage(queue_url).getMessages().get(0).getReceiptHandle();
sqs.changeMessageVisibility(queue_url, receipt, timeout);
}
use of com.amazonaws.services.sqs.AmazonSQS in project aws-doc-sdk-examples by awsdocs.
the class VisibilityTimeout method main.
public static void main(String[] args) {
final String queue_name = "testQueue" + new Date().getTime();
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
// first, create a queue (unless it exists already)
try {
CreateQueueResult cq_result = sqs.createQueue(queue_name);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl();
// Send some messages to the queue
for (int i = 0; i < 20; i++) {
sqs.sendMessage(queue_url, "This is message " + i);
}
// change visibility timeout (single)
changeMessageVisibilitySingle(queue_url, 3600);
// change visibility timeout (multiple)
changeMessageVisibilityMultiple(queue_url, 2000);
}
Aggregations