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);
}
}
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;
}
Aggregations