Search in sources :

Example 1 with Subscription

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

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();
    }
}
Also used : Subscription(com.google.api.services.pubsub.model.Subscription) PubsubOptions(org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions)

Example 3 with Subscription

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();
    }
}
Also used : Subscription(com.google.api.services.pubsub.model.Subscription) PubsubOptions(org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions)

Example 4 with Subscription

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();
}
Also used : Subscription(com.google.api.services.pubsub.model.Subscription)

Example 5 with Subscription

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;
}
Also used : ListSubscriptionsResponse(com.google.api.services.pubsub.model.ListSubscriptionsResponse) ArrayList(java.util.ArrayList) Subscription(com.google.api.services.pubsub.model.Subscription)

Aggregations

Subscription (com.google.api.services.pubsub.model.Subscription)5 PubsubOptions (org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Pubsub (com.google.api.services.pubsub.Pubsub)1 ListSubscriptionsResponse (com.google.api.services.pubsub.model.ListSubscriptionsResponse)1 Topic (com.google.api.services.pubsub.model.Topic)1 ArrayList (java.util.ArrayList)1