use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientSnippets method createSubscription.
/** Example of creating a pull subscription for a topic. */
public Subscription createSubscription(String topicId, String subscriptionId) throws Exception {
// [START pubsub_create_pull_subscription]
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
// eg. projectId = "my-test-project", topicId = "my-test-topic"
TopicName topicName = TopicName.create(projectId, topicId);
// eg. subscriptionId = "my-test-subscription"
SubscriptionName subscriptionName = SubscriptionName.create(projectId, subscriptionId);
// create a pull subscription with default acknowledgement deadline
Subscription subscription = subscriptionAdminClient.createSubscription(subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
return subscription;
}
// [END pubsub_create_pull_subscription]
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class ITSubscriptionAdminClientSnippets method createSubscriptionWithPushIsSuccessful.
@Test
public void createSubscriptionWithPushIsSuccessful() throws Exception {
String topicName = topics[0];
String subscriptionName = subscriptions[0];
createTopic(topicName);
String endpoint = "https://" + projectId + ".appspot.com/push";
Subscription subscription = subscriptionAdminClientSnippets.createSubscriptionWithPushEndpoint(topicName, subscriptionName, endpoint);
assertNotNull(subscription);
Subscription retrievedSubscription = subscriptionAdminClientSnippets.getSubscription(subscriptionName);
assertNotNull(retrievedSubscription);
assertEquals(subscription.getName(), retrievedSubscription.getName());
assertEquals(subscription.getPushConfig().getPushEndpoint(), endpoint);
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class ITSubscriptionAdminClientSnippets method replacePushConfigIsSuccessful.
@Test
public void replacePushConfigIsSuccessful() throws Exception {
String topicName = topics[0];
String subscriptionName = subscriptions[0];
createSubscription(topicName, subscriptionName);
String endpoint = "https://" + projectId + ".appspot.com/push";
subscriptionAdminClientSnippets.replacePushConfig(subscriptionName, endpoint);
Subscription subscription = subscriptionAdminClientSnippets.getSubscription(subscriptionName);
assertNotNull(subscription.getPushConfig());
assertEquals(subscription.getPushConfig().getPushEndpoint(), endpoint);
}
use of com.google.pubsub.v1.SubscriptionName in project google-cloud-java by GoogleCloudPlatform.
the class ITPubSubSnippets method testPublisherSubscriber.
@Test
public void testPublisherSubscriber() throws Exception {
TopicName topicName = TopicName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-topic"));
SubscriptionName subscriptionName = SubscriptionName.create(ServiceOptions.getDefaultProjectId(), formatForTest("test-subscription"));
try (TopicAdminClient publisherClient = TopicAdminClient.create();
SubscriptionAdminClient subscriberClient = SubscriptionAdminClient.create()) {
publisherClient.createTopic(topicName);
subscriberClient.createSubscription(subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
testPublisherSubscriberHelper(topicName, subscriptionName);
subscriberClient.deleteSubscription(subscriptionName);
publisherClient.deleteTopic(topicName);
}
}
use of com.google.pubsub.v1.SubscriptionName 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);
}
Aggregations