Search in sources :

Example 1 with PushConfig

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);
}
Also used : ModifyPushConfigRequest(com.google.pubsub.v1.ModifyPushConfigRequest)

Example 2 with PushConfig

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());
    }
}
Also used : PushConfig(com.google.pubsub.v1.PushConfig) StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) TopicName(com.google.pubsub.v1.TopicName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 3 with PushConfig

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());
}
Also used : PushConfig(com.google.pubsub.v1.PushConfig) TopicNameOneof(com.google.pubsub.v1.TopicNameOneof) SubscriptionName(com.google.pubsub.v1.SubscriptionName) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 4 with PushConfig

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]
}
Also used : PushConfig(com.google.pubsub.v1.PushConfig) SubscriptionAdminClient(com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient) SubscriptionName(com.google.pubsub.v1.SubscriptionName)

Example 5 with PushConfig

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());
}
Also used : PushConfig(com.google.pubsub.v1.PushConfig) Empty(com.google.protobuf.Empty) SubscriptionName(com.google.pubsub.v1.SubscriptionName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ModifyPushConfigRequest(com.google.pubsub.v1.ModifyPushConfigRequest) Test(org.junit.Test)

Aggregations

PushConfig (com.google.pubsub.v1.PushConfig)6 SubscriptionName (com.google.pubsub.v1.SubscriptionName)6 Test (org.junit.Test)4 TopicName (com.google.pubsub.v1.TopicName)3 ApiException (com.google.api.gax.grpc.ApiException)2 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 ModifyPushConfigRequest (com.google.pubsub.v1.ModifyPushConfigRequest)2 Subscription (com.google.pubsub.v1.Subscription)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 Empty (com.google.protobuf.Empty)1 TopicNameOneof (com.google.pubsub.v1.TopicNameOneof)1