当前位置: 首页>>代码示例>>Java>>正文


Java AmazonSQSException类代码示例

本文整理汇总了Java中com.amazonaws.services.sqs.model.AmazonSQSException的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSException类的具体用法?Java AmazonSQSException怎么用?Java AmazonSQSException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AmazonSQSException类属于com.amazonaws.services.sqs.model包,在下文中一共展示了AmazonSQSException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upsertQueue

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
/**
 * Asserts that an SQS queue exists with specific attributes. The queue is created if it does not exist,
 * and any existing queue is modified if the attributes don't match.
 *
 * @param queueConfig  Configuration of the SQS queue
 * @param clientConfig Configuration of the SQS queue client
 * @return an SqsQueue
 */
public Single<SqsQueue<String>> upsertQueue(SqsQueueConfig queueConfig, SqsQueueClientConfig clientConfig) {
    CreateQueueAction action = new CreateQueueAction(queueConfig);
    Single<SqsQueue<String>> output = requestSender.sendRequest(action).map(createQueueResult -> {
        return new BufferedStringSqsQueue(createQueueResult.getQueueUrl(), requestSender, clientConfig);
    });
    return output.onErrorResumeNext((err) -> {
        if (err instanceof AmazonSQSException) {
            AmazonSQSException awsException = (AmazonSQSException) err;
            //Queue already exists, but has wrong attributes. We need to update them.
            if (QUEUE_ALREADY_EXISTS.equals(awsException.getErrorCode())) {
                //Have to get queue from name since we don't know the url yet.
                return getQueueFromName(queueConfig.getName(), queueConfig.getRegion(), clientConfig)
                        .flatMap((queue) -> {
                            return queue.setAttributes(queueConfig.getAttributes()).toSingleDefault(queue);
                        });
            }
        }
        return Single.error(err);
    });
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:29,代码来源:SqsClient.java

示例2: shouldRetry

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
private boolean shouldRetry(int errCount, Throwable error) {
    if (errCount > retryCount) {
        return false;
    }
    if (error instanceof AmazonSQSException) {
        return ((AmazonSQSException) error).getErrorType() == AmazonServiceException.ErrorType.Service;
    }
    return true;
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:10,代码来源:RetryingSqsQueue.java

示例3: sendRequest

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
@Override
public <T> Single<T> sendRequest(SqsAction<T> request) {
    return Single.defer(() -> delegate.sendRequest(request))
            .retry((errCount, error) -> {
                if (errCount > retryCount || request.isBatchAction()) {
                    return false;
                }
                if (error instanceof AmazonSQSException) {
                    return ((AmazonSQSException) error).getErrorType() == AmazonServiceException.ErrorType.Service;
                }
                return true;
            }).subscribeWith(SingleSubject.create());//convert to Hot single
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:14,代码来源:RetryingSqsRequestSender.java

示例4: testAssertQueueUnknownAmazonError

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
@Test
public void testAssertQueueUnknownAmazonError() {
    when(requestSenderMock.sendRequest(any(CreateQueueAction.class))).thenReturn(Single.error(
            new AmazonSQSException("Unknown error")
    ));

    client.upsertQueue(QUEUE_CONFIG).test().assertError(RuntimeException.class);
    verify(requestSenderMock).sendRequest(any(CreateQueueAction.class));
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:10,代码来源:SqsClientTest.java

示例5: testRetryForServerError

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
@Test
public void testRetryForServerError() {
    when(delegateMock.sendRequest(any()))
            .thenThrow(SERVER_EXCEPTION);
    requestSender.sendRequest(actionMock).test().assertError(AmazonSQSException.class);
    verify(delegateMock, times(2)).sendRequest(any());//exactly 2 requests sent
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:8,代码来源:RetryingSqsRequestSenderTest.java

示例6: main

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
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);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:28,代码来源:VisibilityTimeout.java

示例7: main

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
public static void main(String[] args)
{
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    try {
        CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();

    SendMessageRequest send_msg_request = new SendMessageRequest()
            .withQueueUrl(queueUrl)
            .withMessageBody("hello world")
            .withDelaySeconds(5);
    sqs.sendMessage(send_msg_request);


    // Send multiple messages to the queue
    SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest()
            .withQueueUrl(queueUrl)
            .withEntries(
                    new SendMessageBatchRequestEntry(
                            "msg_1", "Hello from message 1"),
                    new SendMessageBatchRequestEntry(
                            "msg_2", "Hello from message 2")
                            .withDelaySeconds(10));
    sqs.sendMessageBatch(send_batch_request);

    // receive messages from the queue
    List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();

    // delete messages from the queue
    for (Message m : messages) {
        sqs.deleteMessage(queueUrl, m.getReceiptHandle());
    }
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:41,代码来源:SendReceiveMessages.java

示例8: main

import com.amazonaws.services.sqs.model.AmazonSQSException; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
       "To run this example, supply the name of a queue to create and\n" +
       "queue url of an existing queue.\n\n" +
       "Ex: LongPolling <unique-queue-name> <existing-queue-url>\n";

    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String queue_name = args[0];
    String queue_url = args[1];

    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    // Enable long polling when creating a queue
    CreateQueueRequest create_request = new CreateQueueRequest()
            .withQueueName(queue_name)
            .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20");

    try {
        sqs.createQueue(create_request);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    // Enable long polling on an existing queue
    SetQueueAttributesRequest set_attrs_request = new SetQueueAttributesRequest()
            .withQueueUrl(queue_url)
            .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20");
    sqs.setQueueAttributes(set_attrs_request);

    // Enable long polling on a message receipt
    ReceiveMessageRequest receive_request = new ReceiveMessageRequest()
            .withQueueUrl(queue_url)
            .withWaitTimeSeconds(20);
    sqs.receiveMessage(receive_request);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:43,代码来源:LongPolling.java


注:本文中的com.amazonaws.services.sqs.model.AmazonSQSException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。