use of com.google.pubsub.v1.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class PublisherSnippets method newBuilder.
/** Example of creating a {@code Publisher}. */
// [TARGET newBuilder(TopicName)]
// [VARIABLE "my_project"]
// [VARIABLE "my_topic"]
public static void newBuilder(String projectId, String topicId) throws Exception {
TopicName topic = TopicName.create(projectId, topicId);
Publisher publisher = Publisher.defaultBuilder(topic).build();
try {
// ...
} finally {
// When finished with the publisher, make sure to shutdown to free up resources.
publisher.shutdown();
}
}
use of com.google.pubsub.v1.TopicName 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.TopicName 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.TopicName 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.TopicName in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method listTopicSubscriptionsTest.
@Test
@SuppressWarnings("all")
public void listTopicSubscriptionsTest() {
String nextPageToken = "";
SubscriptionName subscriptionsElement = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<SubscriptionName> subscriptions = Arrays.asList(subscriptionsElement);
ListTopicSubscriptionsResponse expectedResponse = ListTopicSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptionsWithSubscriptionNameList(subscriptions).build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
ListTopicSubscriptionsPagedResponse pagedListResponse = client.listTopicSubscriptions(topic);
List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
List<SubscriptionName> resourceNames = Lists.newArrayList(pagedListResponse.iterateAllAsSubscriptionName());
Assert.assertEquals(1, resourceNames.size());
Assert.assertEquals(expectedResponse.getSubscriptionsListAsSubscriptionNameList().get(0), resourceNames.get(0));
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTopicSubscriptionsRequest actualRequest = (ListTopicSubscriptionsRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Aggregations