@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
/** * * * <pre> * If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. * </pre> * * <code>.google.pubsub.v1.PushConfig push_config = 4;</code> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_) .mergeFrom(value) .buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * The push configuration for future deliveries. * 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` or `StreamingPull` is not called. * </pre> * * <code>.google.pubsub.v1.PushConfig push_config = 2;</code> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_) .mergeFrom(value) .buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** 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()) { ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId); PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build(); subscriptionAdminClient.modifyPushConfig(subscriptionName, pushConfig); } // [END pubsub_update_push_configuration] }
/** Example of creating a subscription with a push endpoint. */ public Subscription createSubscriptionWithPushEndpoint( String topicId, String subscriptionId, String endpoint) throws Exception { // [START pubsub_create_push_subscription] try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { ProjectTopicName topicName = ProjectTopicName.of(projectId, topicId); ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId); // eg. endpoint = "https://my-test-project.appspot.com/push" PushConfig pushConfig = PushConfig.newBuilder().setPushEndpoint(endpoint).build(); // acknowledgement deadline in seconds for the message received over the push endpoint int ackDeadlineInSeconds = 10; Subscription subscription = subscriptionAdminClient.createSubscription( subscriptionName, topicName, pushConfig, ackDeadlineInSeconds); return subscription; } // [END pubsub_create_push_subscription] }
@Test @SuppressWarnings("all") public void modifyPushConfigExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockSubscriber.addException(exception); try { ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]"); PushConfig pushConfig = PushConfig.newBuilder().build(); client.modifyPushConfig(subscription, pushConfig); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void createSubscriptionExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockSubscriber.addException(exception); try { ProjectSubscriptionName name = ProjectSubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]"); ProjectTopicName topic = ProjectTopicName.of("[PROJECT]", "[TOPIC]"); PushConfig pushConfig = PushConfig.newBuilder().build(); int ackDeadlineSeconds = 2135351438; client.createSubscription(name, topic, pushConfig, ackDeadlineSeconds); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test public void testVPCPushSubscriber() throws Exception { assumeTrue(IS_VPC_TEST); ProjectTopicName topicName = ProjectTopicName.of(projectId, formatForTest("testing-vpc-push-subscriber-topic")); ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of( projectId, formatForTest("testing-vpc-push-subscriber-subscription")); topicAdminClient.createTopic(topicName); try { subscriptionAdminClient.createSubscription( subscriptionName, topicName, PushConfig.newBuilder().setPushEndpoint("random_point").build(), 10); subscriptionAdminClient.deleteSubscription(subscriptionName); Assert.fail("No exception raised"); } catch (PermissionDeniedException e) { // expected } topicAdminClient.deleteTopic(topicName); }
@Test @SuppressWarnings("all") public void modifyPushConfigTest() { Empty expectedResponse = Empty.newBuilder().build(); mockSubscriber.addResponse(expectedResponse); ProjectSubscriptionName subscription = ProjectSubscriptionName.of("[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, ProjectSubscriptionName.parse(actualRequest.getSubscription())); Assert.assertEquals(pushConfig, actualRequest.getPushConfig()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
PushConfig pushConfig = PushConfig.newBuilder().build(); int ackDeadlineSeconds = 2135351438;
subscriptionName, topicName, PushConfig.newBuilder().build(), 10);
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
/** * <pre> * If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. * </pre> * * <code>optional .google.pubsub.v1.PushConfig push_config = 4;</code> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_).mergeFrom(value).buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * <code>optional .google.pubsub.v1.PushConfig push_config = 4;</code> * * <pre> * If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. * </pre> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_).mergeFrom(value).buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * <pre> * The push configuration for future deliveries. * 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. * </pre> * * <code>optional .google.pubsub.v1.PushConfig push_config = 2;</code> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_).mergeFrom(value).buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * <code>optional .google.pubsub.v1.PushConfig push_config = 2;</code> * * <pre> * The push configuration for future deliveries. * 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. * </pre> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_).mergeFrom(value).buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * If push delivery is used with this subscription, this field is * used to configure it. An empty `pushConfig` signifies that the subscriber * will pull and ack messages using API methods. * </pre> * * <code>.google.pubsub.v1.PushConfig push_config = 4;</code> */ public Builder mergePushConfig(com.google.pubsub.v1.PushConfig value) { if (pushConfigBuilder_ == null) { if (pushConfig_ != null) { pushConfig_ = com.google.pubsub.v1.PushConfig.newBuilder(pushConfig_) .mergeFrom(value) .buildPartial(); } else { pushConfig_ = value; } onChanged(); } else { pushConfigBuilder_.mergeFrom(value); } return this; } /**
/** * Create a new subscription on Google Cloud Pub/Sub. * * @param subscriptionName the name of the new subscription * @param topicName the name of the topic being subscribed to * @param ackDeadline deadline in seconds before a message is resent, must be between 10 and 600 seconds. * If not provided, set to default of 10 seconds * @param pushEndpoint the URL of the service receiving the push messages. If not provided, uses * message pulling by default * @return the created subscription */ public Subscription createSubscription(String subscriptionName, String topicName, Integer ackDeadline, String pushEndpoint) { Assert.hasText(subscriptionName, "No subscription name was specified."); Assert.hasText(topicName, "No topic name was specified."); int finalAckDeadline = this.defaultAckDeadline; if (ackDeadline != null) { validateAckDeadline(ackDeadline); finalAckDeadline = ackDeadline; } PushConfig.Builder pushConfigBuilder = PushConfig.newBuilder(); if (pushEndpoint != null) { pushConfigBuilder.setPushEndpoint(pushEndpoint); } return this.subscriptionAdminClient.createSubscription( ProjectSubscriptionName.of(this.projectId, subscriptionName), ProjectTopicName.of(this.projectId, topicName), pushConfigBuilder.build(), finalAckDeadline); }