Search in sources :

Example 16 with TopicAdminClient

use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.

the class ManagerIT method testGetIam.

@Test
public void testGetIam() throws Exception {
    topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
    DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
    DeviceRegistryExample.getIamPermissions(PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    String got = bout.toString();
    Assert.assertTrue(got.contains("ETAG"));
    DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        topicAdminClient.deleteTopic(topic.getNameAsTopicName());
    }
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) Test(org.junit.Test)

Example 17 with TopicAdminClient

use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.

the class ManagerIT method testCreateDeleteEsDevice.

@Test
public void testCreateDeleteEsDevice() throws Exception {
    final String deviceName = "es-device";
    topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
    DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
    DeviceRegistryExample.createDeviceWithEs256(deviceName, ES_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    DeviceRegistryExample.getDeviceStates(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    String got = bout.toString();
    Assert.assertTrue(got.contains("Created device: {"));
    DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        topicAdminClient.deleteTopic(topic.getNameAsTopicName());
    }
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) Test(org.junit.Test)

Example 18 with TopicAdminClient

use of com.google.cloud.pubsub.v1.TopicAdminClient in project java-docs-samples by GoogleCloudPlatform.

the class ManagerIT method testCreateListDevices.

@Test
public void testCreateListDevices() throws Exception {
    final String deviceName = "rsa-device";
    topic = DeviceRegistryExample.createIotTopic(PROJECT_ID, TOPIC_ID);
    DeviceRegistryExample.createRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID, TOPIC_ID);
    DeviceRegistryExample.createDeviceWithRs256(deviceName, RSA_PATH, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    DeviceRegistryExample.listDevices(PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    String got = bout.toString();
    Assert.assertTrue(got.contains("Created device: {"));
    Assert.assertTrue(got.contains("Found"));
    DeviceRegistryExample.deleteDevice(deviceName, PROJECT_ID, CLOUD_REGION, REGISTRY_ID);
    DeviceRegistryExample.deleteRegistry(CLOUD_REGION, PROJECT_ID, REGISTRY_ID);
    try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
        topicAdminClient.deleteTopic(topic.getNameAsTopicName());
    }
}
Also used : TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) Test(org.junit.Test)

Example 19 with TopicAdminClient

use of com.google.cloud.pubsub.v1.TopicAdminClient 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]
}
Also used : TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) Topic(com.google.pubsub.v1.Topic) TopicName(com.google.pubsub.v1.TopicName)

Example 20 with TopicAdminClient

use of com.google.cloud.pubsub.v1.TopicAdminClient 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]
}
Also used : ListTopicsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse) TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) ListTopicsRequest(com.google.pubsub.v1.ListTopicsRequest) Topic(com.google.pubsub.v1.Topic)

Aggregations

TopicAdminClient (com.google.cloud.pubsub.v1.TopicAdminClient)19 Test (org.junit.Test)18 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)12 TopicName (com.google.pubsub.v1.TopicName)8 Topic (com.google.pubsub.v1.Topic)5 Binding (com.google.iam.v1.Binding)2 Policy (com.google.iam.v1.Policy)2 TestIamPermissionsResponse (com.google.iam.v1.TestIamPermissionsResponse)2 SubscriptionName (com.google.pubsub.v1.SubscriptionName)2 LinkedList (java.util.LinkedList)2 ApiException (com.google.api.gax.rpc.ApiException)1 ListTopicSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse)1 ListTopicsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicsPagedResponse)1 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)1 ListTopicSubscriptionsRequest (com.google.pubsub.v1.ListTopicSubscriptionsRequest)1 ListTopicsRequest (com.google.pubsub.v1.ListTopicsRequest)1 ProjectTopicName (com.google.pubsub.v1.ProjectTopicName)1 CallOptions (io.grpc.CallOptions)1 Channel (io.grpc.Channel)1 ClientInterceptor (io.grpc.ClientInterceptor)1