com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequest Java Examples

The following examples show how to use com.amazonaws.services.sqs.model.ChangeMessageVisibilityBatchRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQSScanWorkflow.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public void renewScanRangeTasks(Collection<ScanRangeTask> tasks, Duration ttl) {
    if (tasks.isEmpty()) {
        return;
    }

    int timeout = toSeconds(ttl);
    int id = 0;

    List<ChangeMessageVisibilityBatchRequestEntry> allEntries = Lists.newArrayListWithCapacity(tasks.size());
    for (ScanRangeTask task : tasks) {
        allEntries.add(
                new ChangeMessageVisibilityBatchRequestEntry()
                        .withId(String.valueOf(id++))
                        .withReceiptHandle(((QueueScanRangeTask) task).getMessageId())
                        .withVisibilityTimeout(timeout));
    }

    // Cannot renew more than 10 in a single request
    for (List<ChangeMessageVisibilityBatchRequestEntry> entries : Lists.partition(allEntries, 10)) {
        _sqs.changeMessageVisibilityBatch(new ChangeMessageVisibilityBatchRequest()
                .withQueueUrl(getQueueUrl(_pendingScanRangeQueue))
                .withEntries(entries));
    }
}
 
Example #2
Source File: NegativeAcknowledgerTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Test NegativeAcknowledger action
 */
@Test
public void testAction() throws JMSException {


    List<String> receiptHandles = new ArrayList<String>();
    receiptHandles.add("r0");
    receiptHandles.add("r1");
    receiptHandles.add("r2");

    negativeAcknowledger.action(QUEUE_URL, receiptHandles);

    ArgumentCaptor<ChangeMessageVisibilityBatchRequest> argumentCaptor =
            ArgumentCaptor.forClass(ChangeMessageVisibilityBatchRequest.class);
    verify(amazonSQSClient).changeMessageVisibilityBatch(argumentCaptor.capture());

    assertEquals(1, argumentCaptor.getAllValues().size());

    assertEquals(QUEUE_URL, argumentCaptor.getAllValues().get(0).getQueueUrl());
    List<ChangeMessageVisibilityBatchRequestEntry> captureList =  argumentCaptor.getAllValues().get(0).getEntries();
    assertEquals(receiptHandles.size(), captureList.size());

    for (ChangeMessageVisibilityBatchRequestEntry item : captureList) {
        receiptHandles.contains(item.getReceiptHandle());
    }
}
 
Example #3
Source File: NegativeAcknowledger.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 6 votes vote down vote up
/**
 * Action call block for negative acknowledge for the list of receipt
 * handles. This action can be applied on multiple messages for the same
 * queue.
 * 
 * @param queueUrl
 *            The queueUrl of the queue, which the receipt handles belong.
 * @param receiptHandles
 *            The list of handles, which is be used to negative acknowledge
 *            the messages via using
 *            <code>changeMessageVisibilityBatch</code>.
 * @throws JMSException
 *             If <code>changeMessageVisibilityBatch</code> throws.
 */
@Override
public void action(String queueUrl, List<String> receiptHandles) throws JMSException {

    if (receiptHandles == null || receiptHandles.isEmpty()) {
        return;
    }

    List<ChangeMessageVisibilityBatchRequestEntry> nackEntries = new ArrayList<ChangeMessageVisibilityBatchRequestEntry>(
            receiptHandles.size());
    int batchId = 0;
    for (String messageReceiptHandle : receiptHandles) {
        ChangeMessageVisibilityBatchRequestEntry changeMessageVisibilityBatchRequestEntry = new ChangeMessageVisibilityBatchRequestEntry(
                Integer.toString(batchId), messageReceiptHandle).withVisibilityTimeout(NACK_TIMEOUT);
        nackEntries.add(changeMessageVisibilityBatchRequestEntry);
        batchId++;
    }
    amazonSQSClient.changeMessageVisibilityBatch(new ChangeMessageVisibilityBatchRequest(
            queueUrl, nackEntries));
}
 
Example #4
Source File: QueueImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
        List<ChangeMessageVisibilityBatchRequestEntry> entries,
        ResultCapture<ChangeMessageVisibilityBatchResult> extractor) {

    ChangeMessageVisibilityBatchRequest request = new
            ChangeMessageVisibilityBatchRequest()

        .withEntries(entries);
    return changeMessageVisibilityBatch(request, extractor);
}
 
Example #5
Source File: AmazonSQSMessagingClientWrapperTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 5 votes vote down vote up
@Test(expected = JMSException.class)
public void testChangeMessageVisibilityBatchThrowAmazonServiceException() throws JMSException {

    ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest = new ChangeMessageVisibilityBatchRequest();
    doThrow(new AmazonServiceException("ase"))
            .when(amazonSQSClient).changeMessageVisibilityBatch(eq(changeMessageVisibilityBatchRequest));

    wrapper.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #6
Source File: AmazonSQSMessagingClientWrapperTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 5 votes vote down vote up
@Test(expected = JMSException.class)
public void testChangeMessageVisibilityBatchThrowAmazonClientException() throws JMSException {

    ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest = new ChangeMessageVisibilityBatchRequest();
    doThrow(new AmazonClientException("ace"))
            .when(amazonSQSClient).changeMessageVisibilityBatch(eq(changeMessageVisibilityBatchRequest));

    wrapper.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #7
Source File: AmazonSQSMessagingClientWrapperTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeMessageVisibilityBatch() throws JMSException {

    ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest = new ChangeMessageVisibilityBatchRequest();
    wrapper.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
    verify(amazonSQSClient).changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #8
Source File: AmazonSQSIdleQueueDeletingClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request) {
    // If the queue is deleted, there's no way to change the message visibility.
    try {
        return super.changeMessageVisibilityBatch(request);
    } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) {
        // Try on the alternate queue
        ChangeMessageVisibilityBatchRequest alternateRequest = request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl()));
        return super.changeMessageVisibilityBatch(alternateRequest);
    }
}
 
Example #9
Source File: QueueImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
        ChangeMessageVisibilityBatchRequest request,
        ResultCapture<ChangeMessageVisibilityBatchResult> extractor) {

    ActionResult result =
            resource.performAction("ChangeMessageVisibilityBatch", request,
            extractor);

    if (result == null) return null;
    return (ChangeMessageVisibilityBatchResult) result.getData();
}
 
Example #10
Source File: AmazonSQSExtendedClient.java    From amazon-sqs-java-extended-client-lib with Apache License 2.0 5 votes vote down vote up
/**
 * Simplified method form for invoking the ChangeMessageVisibilityBatch
 * operation.
 *
 * @see #changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest)
 */
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
		String queueUrl,
		java.util.List<ChangeMessageVisibilityBatchRequestEntry> entries) {
	ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest =
			new ChangeMessageVisibilityBatchRequest(queueUrl, entries);
	return changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #11
Source File: ReceiveQueueBuffer.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
protected void nackMessages(Collection<Message> messages) {
    if (messages.isEmpty()) {
        return;
    }

    ChangeMessageVisibilityBatchRequest batchRequest = new ChangeMessageVisibilityBatchRequest().withQueueUrl(sourceQueueUrl);
    // TODO-RS: UserAgent?

    List<ChangeMessageVisibilityBatchRequestEntry> entries = 
            new ArrayList<ChangeMessageVisibilityBatchRequestEntry>(messages.size());

    int i = 0;
    for (Message m : messages) {

        entries.add(new ChangeMessageVisibilityBatchRequestEntry().withId(Integer.toString(i))
                .withReceiptHandle(m.getReceiptHandle()).withVisibilityTimeout(0));
        ++i;
    }

    try {
        batchRequest.setEntries(entries);
        sqsClient.changeMessageVisibilityBatch(batchRequest);
    } catch (AmazonClientException e) {
        // Log and ignore.
        LOG.warn("ReceiveMessageBatchTask: changeMessageVisibility failed " + e);
    }
}
 
Example #12
Source File: QueueImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
        ChangeMessageVisibilityBatchRequest request) {

    return changeMessageVisibilityBatch(request, null);
}
 
Example #13
Source File: SQSSessionTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 4 votes vote down vote up
/**
 * Test recover
 */
@Test
public void testRecover() throws JMSException, InterruptedException {
    sqsSession = new SQSSession(parentSQSConnection, AcknowledgeMode.ACK_UNORDERED);
    when(parentSQSConnection.getNumberOfMessagesToPrefetch()).thenReturn(4);

    when(sqsClientJMSWrapper.getQueueUrl("queue1"))
        .thenReturn(new GetQueueUrlResult().withQueueUrl("queueUrl1"));
    when(sqsClientJMSWrapper.receiveMessage(argThat(new ReceiveRequestMatcher("queueUrl1"))))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message1", "queue1-group1-message1")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message2", "queue1-group2-message2")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message3", "queue1-group3-message3")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message4", "queue1-group1-message4")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message5", "queue1-group2-message5")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message6", "queue1-group3-message6")))
        .thenReturn(new ReceiveMessageResult());
    
    when(sqsClientJMSWrapper.getQueueUrl("queue2"))
        .thenReturn(new GetQueueUrlResult().withQueueUrl("queueUrl2"));
    when(sqsClientJMSWrapper.receiveMessage(argThat(new ReceiveRequestMatcher("queueUrl2"))))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message1", "queue2-group1-message1")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message2", "queue2-group2-message2")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message3", "queue2-group3-message3")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group1", "message4", "queue2-group1-message4")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group2", "message5", "queue2-group2-message5")))
        .thenReturn(new ReceiveMessageResult().withMessages(createFifoMessage("group3", "message6", "queue2-group3-message6")))
        .thenReturn(new ReceiveMessageResult());

    MessageConsumer consumer1 = sqsSession.createConsumer(sqsSession.createQueue("queue1"));
    MessageConsumer consumer2 = sqsSession.createConsumer(sqsSession.createQueue("queue2"));
    final CountDownLatch listenerRelease = new CountDownLatch(1);
    consumer2.setMessageListener(new MessageListener() {
        @Override
        public void onMessage(Message message) {
            try {
                listenerRelease.await();
            } catch (InterruptedException e) {
            }
        }
    });
    
    sqsSession.start();
    
    Message message1 = consumer1.receive();
    
    //let's give a moment for the background threads to:
    //prefetch another message for queue1
    //dispatch message to listener for queue2
    //prefetch another message for queue2
    Thread.sleep(100);
    /*
     * Recover
     */
    sqsSession.recover();
    
    //at this point we have two unacked messages:
    //queue1-group1-message1
    //queue2-group1-message1
    //and we should have 4 more messages prefetched for queue1:
    //queue1-group2-message2
    //queue1-group3-message3
    //queue1-group1-message4
    //queue1-group2-message5
    //and we should have 4 more callbacks scheduled for queue2:
    //queue2-group2-message2
    //queue2-group3-message3
    //queue2-group1-message4
    //queue2-group2-message5
    //after calling recovery, we should nack the two unacked messages and all other messages for the same queue / group, so these:
    //queue1-group1-message1
    //queue2-group1-message1
    //queue1-group1-message4
    //queue2-group1-message4
    
    ArgumentCaptor<ChangeMessageVisibilityBatchRequest> changeVisibilityCaptor = ArgumentCaptor.forClass(ChangeMessageVisibilityBatchRequest.class);
    verify(sqsClientJMSWrapper, times(2)).changeMessageVisibilityBatch(changeVisibilityCaptor.capture());
    List<ChangeMessageVisibilityBatchRequest> changeVisibilityRequests = changeVisibilityCaptor.getAllValues();
    
    Set<String> handles = new HashSet<String>();
    for (ChangeMessageVisibilityBatchRequest request : changeVisibilityRequests) {
        for (ChangeMessageVisibilityBatchRequestEntry entry : request.getEntries()) {
            handles.add(entry.getReceiptHandle());
        }
    }
    
    assertEquals(4, handles.size());
    assertTrue(handles.contains("queue1-group1-message1"));
    assertTrue(handles.contains("queue1-group1-message4"));
    assertTrue(handles.contains("queue2-group1-message1"));
    assertTrue(handles.contains("queue2-group1-message4"));
    
    listenerRelease.countDown();
    
    sqsSession.close();
}
 
Example #14
Source File: AbstractAmazonSQSClientWrapperTest.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 4 votes vote down vote up
@Test
public void changeMessageVisibilityBatch() {
    assertWrappedMethod(AmazonSQS::changeMessageVisibilityBatch, new ChangeMessageVisibilityBatchRequest());
}
 
Example #15
Source File: AbstractAmazonSQSClientWrapper.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 4 votes vote down vote up
@Override
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request) {
    request.getRequestClientOptions().appendUserAgent(userAgent);
    return amazonSqsToBeExtended.changeMessageVisibilityBatch(request);
}
 
Example #16
Source File: AmazonSQSExtendedClient.java    From amazon-sqs-java-extended-client-lib with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Changes the visibility timeout of multiple messages. This is a batch
 * version of ChangeMessageVisibility. The result of the action on each
 * message is reported individually in the response. You can send up to 10
 * ChangeMessageVisibility requests with each
 * <code>ChangeMessageVisibilityBatch</code> action.
 * </p>
 * <p>
 * <b>IMPORTANT:</b>Because the batch request can result in a combination of
 * successful and unsuccessful actions, you should check for batch errors
 * even when the call returns an HTTP status code of 200.
 * </p>
 * <p>
 * <b>NOTE:</b>Some API actions take lists of parameters. These lists are
 * specified using the param.n notation. Values of n are integers starting
 * from 1. For example, a parameter list with two elements looks like this:
 * </p>
 * <p>
 * <code>&Attribute.1=this</code>
 * </p>
 * <p>
 * <code>&Attribute.2=that</code>
 * </p>
 *
 * @param changeMessageVisibilityBatchRequest
 *            Container for the necessary parameters to execute the
 *            ChangeMessageVisibilityBatch service method on AmazonSQS.
 *
 * @return The response from the ChangeMessageVisibilityBatch service
 *         method, as returned by AmazonSQS.
 *
 * @throws BatchEntryIdsNotDistinctException
 * @throws TooManyEntriesInBatchRequestException
 * @throws InvalidBatchEntryIdException
 * @throws EmptyBatchRequestException
 *
 * @throws AmazonClientException
 *             If any internal errors are encountered inside the client
 *             while attempting to make the request or handle the response.
 *             For example if a network connection is not available.
 * @throws AmazonServiceException
 *             If an error response is returned by AmazonSQS indicating
 *             either a problem with the data in the request, or a server
 *             side issue.
 */
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
		ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException,
		AmazonClientException {

	for (ChangeMessageVisibilityBatchRequestEntry entry : changeMessageVisibilityBatchRequest.getEntries()) {
		if (isS3ReceiptHandle(entry.getReceiptHandle())) {
			entry.setReceiptHandle(getOrigReceiptHandle(entry.getReceiptHandle()));
		}
	}

	return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #17
Source File: AmazonSQSMessagingClientWrapper.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Calls <code>changeMessageVisibilityBatch</code> and wraps <code>AmazonClientException</code>. This is
 * used to for negative acknowledge of messages in batch, so that messages
 * can be received again without any delay.
 * 
 * @param changeMessageVisibilityBatchRequest
 *            Container for the necessary parameters to execute the
 *            changeMessageVisibilityBatch service method on AmazonSQS.
 * @return The response from the changeMessageVisibilityBatch service
 *         method, as returned by AmazonSQS.
 * @throws JMSException
 */
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest)
        throws JMSException {
    try {
        prepareRequest(changeMessageVisibilityBatchRequest);
        return amazonSQSClient.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
    } catch (AmazonClientException e) {
        throw handleException(e, "changeMessageVisibilityBatch");
    }
}
 
Example #18
Source File: AmazonSQSExtendedClientBase.java    From amazon-sqs-java-extended-client-lib with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Changes the visibility timeout of multiple messages. This is a batch
 * version of ChangeMessageVisibility. The result of the action on each
 * message is reported individually in the response. You can send up to 10
 * ChangeMessageVisibility requests with each
 * <code>ChangeMessageVisibilityBatch</code> action.
 * </p>
 * <p>
 * <b>IMPORTANT:</b>Because the batch request can result in a combination of
 * successful and unsuccessful actions, you should check for batch errors
 * even when the call returns an HTTP status code of 200.
 * </p>
 * <p>
 * <b>NOTE:</b>Some API actions take lists of parameters. These lists are
 * specified using the param.n notation. Values of n are integers starting
 * from 1. For example, a parameter list with two elements looks like this:
 * </p>
 * <p>
 * <code>&Attribute.1=this</code>
 * </p>
 * <p>
 * <code>&Attribute.2=that</code>
 * </p>
 *
 * @param changeMessageVisibilityBatchRequest
 *            Container for the necessary parameters to execute the
 *            ChangeMessageVisibilityBatch service method on AmazonSQS.
 * 
 * @return The response from the ChangeMessageVisibilityBatch service
 *         method, as returned by AmazonSQS.
 * 
 * @throws BatchEntryIdsNotDistinctException
 * @throws TooManyEntriesInBatchRequestException
 * @throws InvalidBatchEntryIdException
 * @throws EmptyBatchRequestException
 *
 * @throws AmazonClientException
 *             If any internal errors are encountered inside the client
 *             while attempting to make the request or handle the response.
 *             For example if a network connection is not available.
 * @throws AmazonServiceException
 *             If an error response is returned by AmazonSQS indicating
 *             either a problem with the data in the request, or a server
 *             side issue.
 */
public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
		ChangeMessageVisibilityBatchRequest changeMessageVisibilityBatchRequest) throws AmazonServiceException,
		AmazonClientException {

	return amazonSqsToBeExtended.changeMessageVisibilityBatch(changeMessageVisibilityBatchRequest);
}
 
Example #19
Source File: NegativeAcknowledgerTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 3 votes vote down vote up
/**
 * Test NegativeAcknowledger action  withe empty receipt handles
 */
@Test
public void testActionEmptyReceiptHandles() throws JMSException {

    negativeAcknowledger.action(QUEUE_URL, null);

    negativeAcknowledger.action(QUEUE_URL, Collections.EMPTY_LIST);

    verify(amazonSQSClient, never()).changeMessageVisibilityBatch(any(ChangeMessageVisibilityBatchRequest.class));
}
 
Example #20
Source File: Queue.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>ChangeMessageVisibilityBatch</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Queue</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>QueueUrl</code></b>
 *         - mapped from the <code>Url</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see ChangeMessageVisibilityBatchRequest
 */
ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
        ChangeMessageVisibilityBatchRequest request);
 
Example #21
Source File: Queue.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>ChangeMessageVisibilityBatch</code> action and use a
 * ResultCapture to retrieve the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Queue</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>QueueUrl</code></b>
 *         - mapped from the <code>Url</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see ChangeMessageVisibilityBatchRequest
 */
ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(
        ChangeMessageVisibilityBatchRequest request,
        ResultCapture<ChangeMessageVisibilityBatchResult> extractor);