use of com.google.api.services.pubsub.model.Subscription 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.Subscription in project beam by apache.
the class ExampleUtils method setupPubsubSubscription.
private void setupPubsubSubscription(String topic, String subscription) throws IOException {
if (pubsubClient == null) {
pubsubClient = newPubsubClient(options.as(PubsubOptions.class)).build();
}
if (executeNullIfNotFound(pubsubClient.projects().subscriptions().get(subscription)) == null) {
Subscription subInfo = new Subscription().setAckDeadlineSeconds(60).setTopic(topic);
pubsubClient.projects().subscriptions().create(subscription, subInfo).execute();
}
}
use of com.google.api.services.pubsub.model.Subscription in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class ExampleUtils method setupPubsubSubscription.
private void setupPubsubSubscription(String topic, String subscription) throws IOException {
if (pubsubClient == null) {
pubsubClient = newPubsubClient(options.as(PubsubOptions.class)).build();
}
if (executeNullIfNotFound(pubsubClient.projects().subscriptions().get(subscription)) == null) {
Subscription subInfo = new Subscription().setAckDeadlineSeconds(60).setTopic(topic);
pubsubClient.projects().subscriptions().create(subscription, subInfo).execute();
}
}
use of com.google.api.services.pubsub.model.Subscription in project beam by apache.
the class PubsubJsonClient method createSubscription.
@Override
public void createSubscription(TopicPath topic, SubscriptionPath subscription, int ackDeadlineSeconds) throws IOException {
Subscription request = new Subscription().setTopic(topic.getPath()).setAckDeadlineSeconds(ackDeadlineSeconds);
pubsub.projects().subscriptions().create(subscription.getPath(), request).execute();
}
use of com.google.api.services.pubsub.model.Subscription in project beam by apache.
the class PubsubJsonClient method listSubscriptions.
@Override
public List<SubscriptionPath> listSubscriptions(ProjectPath project, TopicPath topic) throws IOException {
ListSubscriptionsResponse response = pubsub.projects().subscriptions().list(project.getPath()).execute();
if (response.getSubscriptions() == null || response.getSubscriptions().isEmpty()) {
return ImmutableList.of();
}
List<SubscriptionPath> subscriptions = new ArrayList<>(response.getSubscriptions().size());
for (Subscription subscription : response.getSubscriptions()) {
if (subscription.getTopic().equals(topic.getPath())) {
subscriptions.add(subscriptionPathFromPath(subscription.getName()));
}
}
return subscriptions;
}
Aggregations