use of com.google.pubsub.v1.AcknowledgeRequest in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method acknowledgeTest.
@Test
@SuppressWarnings("all")
public void acknowledgeTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<String> ackIds = new ArrayList<>();
client.acknowledge(subscription, ackIds);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
AcknowledgeRequest actualRequest = (AcknowledgeRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(ackIds, actualRequest.getAckIdsList());
}
use of com.google.pubsub.v1.AcknowledgeRequest in project spring-cloud-gcp by spring-cloud.
the class PubSubTemplate method pull.
/**
* Pulls messages synchronously, on demand, using the pull request in argument.
*
* <p>This method acknowledges all received messages.
* @param pullRequest pull request containing the subscription name
* @return the list of {@link PubsubMessage} containing the headers and payload
*/
private List<PubsubMessage> pull(PullRequest pullRequest, RetrySettings retrySettings) {
Assert.notNull(pullRequest, "The pull request cannot be null.");
try {
SubscriberStub subscriber = this.subscriberFactory.createSubscriberStub(retrySettings);
Assert.notNull(subscriber, "A SubscriberStub is needed to execute the pull request.");
PullResponse pullResponse = subscriber.pullCallable().call(pullRequest);
// Ack received messages.
if (pullResponse.getReceivedMessagesCount() > 0) {
List<String> ackIds = pullResponse.getReceivedMessagesList().stream().map(ReceivedMessage::getAckId).collect(Collectors.toList());
AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder().setSubscription(pullRequest.getSubscription()).addAllAckIds(ackIds).build();
subscriber.acknowledgeCallable().call(acknowledgeRequest);
}
return pullResponse.getReceivedMessagesList().stream().map(ReceivedMessage::getMessage).collect(Collectors.toList());
} catch (Exception ioe) {
throw new PubSubException("Error pulling messages from subscription " + pullRequest.getSubscription() + ".", ioe);
}
}
use of com.google.pubsub.v1.AcknowledgeRequest in project flink by apache.
the class BlockingGrpcPubSubSubscriber method acknowledge.
@Override
public void acknowledge(List<String> acknowledgementIds) {
if (acknowledgementIds.isEmpty()) {
return;
}
// grpc servers won't accept acknowledge requests that are too large so we split the ackIds
Tuple2<List<String>, List<String>> splittedAckIds = splitAckIds(acknowledgementIds);
while (!splittedAckIds.f0.isEmpty()) {
AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder().setSubscription(projectSubscriptionName).addAllAckIds(splittedAckIds.f0).build();
stub.withDeadlineAfter(60, SECONDS).acknowledge(acknowledgeRequest);
splittedAckIds = splitAckIds(splittedAckIds.f1);
}
}
use of com.google.pubsub.v1.AcknowledgeRequest in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClient method acknowledge.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Acknowledges the messages associated with the `ack_ids` in the `AcknowledgeRequest`. The
* Pub/Sub system can remove the relevant messages from the subscription.
*
* <p>Acknowledging a message whose ack deadline has expired may succeed, but such a message may
* be redelivered later. Acknowledging a message more than once will not result in an error.
*
* <p>Sample code:
*
* <pre><code>
* try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
* SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
* List<String> ackIds = new ArrayList<>();
* subscriptionAdminClient.acknowledge(subscription, ackIds);
* }
* </code></pre>
*
* @param subscription The subscription whose message is being acknowledged. Format is
* `projects/{project}/subscriptions/{sub}`.
* @param ackIds The acknowledgment ID for the messages being acknowledged that was returned by
* the Pub/Sub system in the `Pull` response. Must not be empty.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
/* package-private */
final void acknowledge(SubscriptionName subscription, List<String> ackIds) {
AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).addAllAckIds(ackIds).build();
acknowledge(request);
}
use of com.google.pubsub.v1.AcknowledgeRequest in project beam by apache.
the class PubsubGrpcClient method acknowledge.
@Override
public void acknowledge(SubscriptionPath subscription, List<String> ackIds) throws IOException {
AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription.getPath()).addAllAckIds(ackIds).build();
// ignore Empty result.
subscriberStub().acknowledge(request);
}
Aggregations