Search in sources :

Example 1 with Topic

use of com.google.api.services.pubsub.model.Topic in project camel by apache.

the class PubsubTestSupport method createTopicSubscriptionPair.

public static void createTopicSubscriptionPair(String topicName, String subscriptionName, int ackDealineSeconds) throws Exception {
    Pubsub pubsub = new GooglePubsubConnectionFactory().setServiceAccount(SERVICE_ACCOUNT).setServiceAccountKey(SERVICE_KEY).setServiceURL(SERVICE_URL).getDefaultClient();
    String topicFullName = String.format("projects/%s/topics/%s", PubsubTestSupport.PROJECT_ID, topicName);
    String subscriptionFullName = String.format("projects/%s/subscriptions/%s", PubsubTestSupport.PROJECT_ID, subscriptionName);
    try {
        pubsub.projects().topics().create(topicFullName, new Topic()).execute();
    } catch (Exception e) {
        handleAlreadyExistsException(e);
    }
    try {
        Subscription subscription = new Subscription().setTopic(topicFullName).setAckDeadlineSeconds(ackDealineSeconds);
        pubsub.projects().subscriptions().create(subscriptionFullName, subscription).execute();
    } catch (Exception e) {
        handleAlreadyExistsException(e);
    }
}
Also used : Pubsub(com.google.api.services.pubsub.Pubsub) Topic(com.google.api.services.pubsub.model.Topic) Subscription(com.google.api.services.pubsub.model.Subscription) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException)

Example 2 with Topic

use of com.google.api.services.pubsub.model.Topic in project beam by apache.

the class PubsubJsonClient method listTopics.

@Override
public List<TopicPath> listTopics(ProjectPath project) throws IOException {
    ListTopicsResponse response = pubsub.projects().topics().list(project.getPath()).execute();
    if (response.getTopics() == null || response.getTopics().isEmpty()) {
        return ImmutableList.of();
    }
    List<TopicPath> topics = new ArrayList<>(response.getTopics().size());
    for (Topic topic : response.getTopics()) {
        topics.add(topicPathFromPath(topic.getName()));
    }
    return topics;
}
Also used : ArrayList(java.util.ArrayList) ListTopicsResponse(com.google.api.services.pubsub.model.ListTopicsResponse) Topic(com.google.api.services.pubsub.model.Topic)

Aggregations

Topic (com.google.api.services.pubsub.model.Topic)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Pubsub (com.google.api.services.pubsub.Pubsub)1 ListTopicsResponse (com.google.api.services.pubsub.model.ListTopicsResponse)1 Subscription (com.google.api.services.pubsub.model.Subscription)1 ArrayList (java.util.ArrayList)1