use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientTest method deleteTopicTest.
@Test
@SuppressWarnings("all")
public void deleteTopicTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockPublisher.addResponse(expectedResponse);
TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
client.deleteTopic(topic);
List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteTopicRequest actualRequest = (DeleteTopicRequest) actualRequests.get(0);
Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method getSubscriptionTest.
@Test
@SuppressWarnings("all")
public void getSubscriptionTest() {
SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
TopicNameOneof topic = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
int ackDeadlineSeconds = 2135351438;
boolean retainAckedMessages = false;
Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name).setTopicWithTopicNameOneof(topic).setAckDeadlineSeconds(ackDeadlineSeconds).setRetainAckedMessages(retainAckedMessages).build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
Subscription actualResponse = client.getSubscription(subscription);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetSubscriptionRequest actualRequest = (GetSubscriptionRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method getTopic.
/** Example of getting a topic. */
public Topic getTopic(String topicId) throws Exception {
// [START pubsub_get_topic]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
TopicName topicName = TopicName.create(projectId, topicId);
Topic topic = topicAdminClient.getTopic(topicName);
return topic;
}
// [END pubsub_get_topic]
}
use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method listTopics.
/** Example of listing topics. */
public ListTopicsPagedResponse listTopics() throws Exception {
// [START pubsub_list_topics]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
ListTopicsRequest listTopicsRequest = ListTopicsRequest.newBuilder().setProjectWithProjectName(ProjectName.create(projectId)).build();
ListTopicsPagedResponse response = topicAdminClient.listTopics(listTopicsRequest);
Iterable<Topic> topics = response.iterateAll();
for (Topic topic : topics) {
// do something with the topic
}
return response;
}
// [END pubsub_list_topics]
}
use of com.google.pubsub.v1.Topic in project google-cloud-java by GoogleCloudPlatform.
the class TopicAdminClientSnippets method createTopic.
/** Example of creating a topic. */
public Topic createTopic(String topicId) throws Exception {
// [START pubsub_create_topic]
try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
// projectId <= unique project identifier, eg. "my-project-id"
// topicId <= "my-topic-id"
TopicName topicName = TopicName.create(projectId, topicId);
Topic topic = topicAdminClient.createTopic(topicName);
return topic;
}
// [END pubsub_create_topic]
}
Aggregations