use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClient method modifyAckDeadline.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Modifies the ack deadline for a specific message. This method is useful to indicate that more
* time is needed to process a message by the subscriber, or to make the message available for
* redelivery if the processing was interrupted. Note that this does not modify the
* subscription-level `ackDeadlineSeconds` used for subsequent messages.
*
* <p>Sample code:
*
* <pre><code>
* try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
* SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
* List<String> ackIds = new ArrayList<>();
* int ackDeadlineSeconds = 0;
* subscriptionAdminClient.modifyAckDeadline(subscription, ackIds, ackDeadlineSeconds);
* }
* </code></pre>
*
* @param subscription The name of the subscription. Format is
* `projects/{project}/subscriptions/{sub}`.
* @param ackIds List of acknowledgment IDs.
* @param ackDeadlineSeconds The new ack deadline with respect to the time this request was sent
* to the Pub/Sub system. For example, if the value is 10, the new ack deadline will expire 10
* seconds after the `ModifyAckDeadline` call was made. Specifying zero may immediately make
* the message available for another pull request. The minimum deadline you can specify is 0
* seconds. The maximum deadline you can specify is 600 seconds (10 minutes).
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
/* package-private */
final void modifyAckDeadline(SubscriptionName subscription, List<String> ackIds, int ackDeadlineSeconds) {
ModifyAckDeadlineRequest request = ModifyAckDeadlineRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).addAllAckIds(ackIds).setAckDeadlineSeconds(ackDeadlineSeconds).build();
modifyAckDeadline(request);
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class ITPubSubTest method testPublishSubscribe.
@Test
public void testPublishSubscribe() throws Exception {
TopicName topicName = TopicName.create(projectId, formatForTest("testing-publish-subscribe-topic"));
SubscriptionName subscriptionName = SubscriptionName.create(projectId, formatForTest("testing-publish-subscribe-subscription"));
topicAdminClient.createTopic(topicName);
subscriptionAdminClient.createSubscription(subscriptionName, topicName, PushConfig.newBuilder().build(), 10);
PubsubMessage message = PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("my message")).build();
final SettableApiFuture<PubsubMessage> received = SettableApiFuture.create();
Subscriber subscriber = Subscriber.defaultBuilder(subscriptionName, new MessageReceiver() {
@Override
public void receiveMessage(final PubsubMessage message, final AckReplyConsumer consumer) {
if (received.set(message)) {
consumer.ack();
} else {
consumer.nack();
}
}
}).build();
subscriber.addListener(new Subscriber.Listener() {
public void failed(Subscriber.State from, Throwable failure) {
received.setException(failure);
}
}, MoreExecutors.directExecutor());
subscriber.startAsync();
Publisher publisher = Publisher.defaultBuilder(topicName).build();
publisher.publish(message).get();
publisher.shutdown();
assertEquals(received.get().getData(), message.getData());
subscriber.stopAsync().awaitTerminated();
subscriptionAdminClient.deleteSubscription(subscriptionName);
topicAdminClient.deleteTopic(topicName);
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method pullExceptionTest.
@Test
@SuppressWarnings("all")
public void pullExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
boolean returnImmediately = false;
int maxMessages = 496131527;
client.pull(subscription, returnImmediately, maxMessages);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSubscriptionExceptionTest.
@Test
@SuppressWarnings("all")
public void createSubscriptionExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 2135351438;
client.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method pullTest.
@Test
@SuppressWarnings("all")
public void pullTest() {
PullResponse expectedResponse = PullResponse.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
boolean returnImmediately = false;
int maxMessages = 496131527;
PullResponse actualResponse = client.pull(subscription, returnImmediately, maxMessages);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
PullRequest actualRequest = (PullRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(returnImmediately, actualRequest.getReturnImmediately());
Assert.assertEquals(maxMessages, actualRequest.getMaxMessages());
}
Aggregations