use of com.google.pubsub.v1.PushConfig in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClient method modifyPushConfig.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Modifies the `PushConfig` for a specified subscription.
*
* <p>This may be used to change a push subscription to a pull one (signified by an empty
* `PushConfig`) or vice versa, or change the endpoint URL and other attributes of a push
* subscription. Messages will accumulate for delivery continuously through the call regardless of
* changes to the `PushConfig`.
*
* <p>Sample code:
*
* <pre><code>
* try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
* SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
* PushConfig pushConfig = PushConfig.newBuilder().build();
* subscriptionAdminClient.modifyPushConfig(subscription, pushConfig);
* }
* </code></pre>
*
* @param subscription The name of the subscription. Format is
* `projects/{project}/subscriptions/{sub}`.
* @param pushConfig The push configuration for future deliveries.
* <p>An empty `pushConfig` indicates that the Pub/Sub system should stop pushing messages
* from the given subscription and allow messages to be pulled and acknowledged - effectively
* pausing the subscription if `Pull` is not called.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void modifyPushConfig(SubscriptionName subscription, PushConfig pushConfig) {
ModifyPushConfigRequest request = ModifyPushConfigRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).setPushConfig(pushConfig).build();
modifyPushConfig(request);
}
use of com.google.pubsub.v1.PushConfig 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.PushConfig in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSubscriptionTest.
@Test
@SuppressWarnings("all")
public void createSubscriptionTest() {
SubscriptionName name2 = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicNameOneof topic2 = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
int ackDeadlineSeconds2 = -921632575;
boolean retainAckedMessages = false;
Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name2).setTopicWithTopicNameOneof(topic2).setAckDeadlineSeconds(ackDeadlineSeconds2).setRetainAckedMessages(retainAckedMessages).build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
PushConfig pushConfig = PushConfig.newBuilder().build();
int ackDeadlineSeconds = 2135351438;
Subscription actualResponse = client.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
Subscription actualRequest = (Subscription) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsSubscriptionName());
Assert.assertEquals(TopicNameOneof.from(topic), actualRequest.getTopicAsTopicNameOneof());
Assert.assertEquals(pushConfig, actualRequest.getPushConfig());
Assert.assertEquals(ackDeadlineSeconds, actualRequest.getAckDeadlineSeconds());
}
use of com.google.pubsub.v1.PushConfig in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method replacePushConfig.
/** Example of replacing the push configuration of a subscription, setting the push endpoint. */
public void replacePushConfig(String subscriptionId, String endpoint) throws Exception {
// [START pubsub_update_push_configuration]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build();
subscriptionAdminClient.modifyPushConfig(subscriptionName, pushConfig);
}
// [END pubsub_update_push_configuration]
}
use of com.google.pubsub.v1.PushConfig in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method modifyPushConfigTest.
@Test
@SuppressWarnings("all")
public void modifyPushConfigTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
PushConfig pushConfig = PushConfig.newBuilder().build();
client.modifyPushConfig(subscription, pushConfig);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
ModifyPushConfigRequest actualRequest = (ModifyPushConfigRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(pushConfig, actualRequest.getPushConfig());
}
Aggregations