Search in sources :

Example 1 with CreateQueueResult

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);
}
Also used : CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult)

Example 2 with CreateQueueResult

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);
    }
}
Also used : PurgeQueueRequest(com.amazonaws.services.sqs.model.PurgeQueueRequest) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult)

Example 3 with CreateQueueResult

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;
}
Also used : Policy(com.amazonaws.auth.policy.Policy) GetQueueAttributesResult(com.amazonaws.services.sqs.model.GetQueueAttributesResult) GetQueueAttributesRequest(com.amazonaws.services.sqs.model.GetQueueAttributesRequest) HashMap(java.util.HashMap) Statement(com.amazonaws.auth.policy.Statement) CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) Resource(com.amazonaws.auth.policy.Resource) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) SetQueueAttributesRequest(com.amazonaws.services.sqs.model.SetQueueAttributesRequest)

Example 4 with CreateQueueResult

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();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 5 with CreateQueueResult

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);
}
Also used : AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) Date(java.util.Date) AmazonSQSException(com.amazonaws.services.sqs.model.AmazonSQSException)

Aggregations

CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)8 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)3 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)2 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 Policy (com.amazonaws.auth.policy.Policy)1 Resource (com.amazonaws.auth.policy.Resource)1 Statement (com.amazonaws.auth.policy.Statement)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 GetQueueAttributesRequest (com.amazonaws.services.sqs.model.GetQueueAttributesRequest)1 GetQueueAttributesResult (com.amazonaws.services.sqs.model.GetQueueAttributesResult)1 Message (com.amazonaws.services.sqs.model.Message)1 PurgeQueueRequest (com.amazonaws.services.sqs.model.PurgeQueueRequest)1 SendMessageBatchRequest (com.amazonaws.services.sqs.model.SendMessageBatchRequest)1 SendMessageBatchRequestEntry (com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1 SetQueueAttributesRequest (com.amazonaws.services.sqs.model.SetQueueAttributesRequest)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1