use of com.amazonaws.services.sqs.model.CreateQueueResult in project camel by apache.
the class SqsEndpoint method createQueue.
protected void createQueue(AmazonSQS client) {
LOG.trace("Queue '{}' doesn't exist. Will create it...", configuration.getQueueName());
// creates a new queue, or returns the URL of an existing one
CreateQueueRequest request = new CreateQueueRequest(configuration.getQueueName());
if (getConfiguration().getDefaultVisibilityTimeout() != null) {
request.getAttributes().put(QueueAttributeName.VisibilityTimeout.name(), String.valueOf(getConfiguration().getDefaultVisibilityTimeout()));
}
if (getConfiguration().getMaximumMessageSize() != null) {
request.getAttributes().put(QueueAttributeName.MaximumMessageSize.name(), String.valueOf(getConfiguration().getMaximumMessageSize()));
}
if (getConfiguration().getMessageRetentionPeriod() != null) {
request.getAttributes().put(QueueAttributeName.MessageRetentionPeriod.name(), String.valueOf(getConfiguration().getMessageRetentionPeriod()));
}
if (getConfiguration().getPolicy() != null) {
request.getAttributes().put(QueueAttributeName.Policy.name(), String.valueOf(getConfiguration().getPolicy()));
}
if (getConfiguration().getReceiveMessageWaitTimeSeconds() != null) {
request.getAttributes().put(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), String.valueOf(getConfiguration().getReceiveMessageWaitTimeSeconds()));
}
if (getConfiguration().getRedrivePolicy() != null) {
request.getAttributes().put(QueueAttributeName.RedrivePolicy.name(), getConfiguration().getRedrivePolicy());
}
LOG.trace("Creating queue [{}] with request [{}]...", configuration.getQueueName(), request);
CreateQueueResult queueResult = client.createQueue(request);
queueUrl = queueResult.getQueueUrl();
LOG.trace("Queue created and available at: {}", queueUrl);
}
use of com.amazonaws.services.sqs.model.CreateQueueResult in project apex-malhar by apache.
the class SQSTestBase method produceMsg.
public void produceMsg(String[] msgs, boolean purgeFirst) throws Exception {
CreateQueueResult res = sqs.createQueue(getCurrentQueueName());
if (purgeFirst) {
PurgeQueueRequest purgeReq = new PurgeQueueRequest(res.getQueueUrl());
sqs.purgeQueue(purgeReq);
}
for (String text : msgs) {
sqs.sendMessage(res.getQueueUrl(), text);
}
}
use of com.amazonaws.services.sqs.model.CreateQueueResult in project glacier-cli by carlossg.
the class Glacier method setupSQS.
// ==============
// Helper methods
// ==============
private QueueConfig setupSQS(String sqsQueueName) {
QueueConfig config = new QueueConfig();
CreateQueueRequest request = new CreateQueueRequest().withQueueName(sqsQueueName);
CreateQueueResult result = sqsClient.createQueue(request);
config.sqsQueueURL = result.getQueueUrl();
GetQueueAttributesRequest qRequest = new GetQueueAttributesRequest().withQueueUrl(config.sqsQueueURL).withAttributeNames("QueueArn");
GetQueueAttributesResult qResult = sqsClient.getQueueAttributes(qRequest);
config.sqsQueueARN = qResult.getAttributes().get("QueueArn");
Policy sqsPolicy = new Policy().withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers).withActions(SQSActions.SendMessage).withResources(new Resource(config.sqsQueueARN)));
Map<String, String> queueAttributes = new HashMap<String, String>();
queueAttributes.put("Policy", sqsPolicy.toJson());
sqsClient.setQueueAttributes(new SetQueueAttributesRequest(config.sqsQueueURL, queueAttributes));
return config;
}
use of com.amazonaws.services.sqs.model.CreateQueueResult in project beam by apache.
the class EmbeddedSqsServer method before.
@Override
protected void before() {
sqsRestServer = SQSRestServerBuilder.withDynamicPort().start();
int port = sqsRestServer.waitUntilStarted().localAddress().getPort();
String endpoint = String.format("http://localhost:%d", port);
String region = "elasticmq";
String accessKey = "x";
String secretKey = "x";
client = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))).withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region)).build();
final CreateQueueResult queue = client.createQueue("test");
queueUrl = queue.getQueueUrl();
}
use of com.amazonaws.services.sqs.model.CreateQueueResult 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)
// 1 hour
changeMessageVisibilitySingle(queue_url, 60 * 60);
// change visibility timeout (multiple)
// 30 minutes
changeMessageVisibilityMultiple(queue_url, 30 * 60);
}
Aggregations