Search in sources :

Example 1 with ChannelProvider

use of com.google.api.gax.grpc.ChannelProvider in project google-cloud-java by GoogleCloudPlatform.

the class SubscriberSnippets method createSubscriberWithCustomCredentials.

private Subscriber createSubscriberWithCustomCredentials() throws Exception {
    // [START pubsub_subscriber_custom_credentials]
    CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream("credentials.json")));
    ChannelProvider channelProvider = TopicAdminSettings.defaultChannelProviderBuilder().setCredentialsProvider(credentialsProvider).build();
    Subscriber subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).setChannelProvider(channelProvider).build();
    // [START pubsub_subscriber_custom_credentials]
    return subscriber;
}
Also used : Subscriber(com.google.cloud.pubsub.spi.v1.Subscriber) ChannelProvider(com.google.api.gax.grpc.ChannelProvider) FixedCredentialsProvider(com.google.api.gax.core.FixedCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) FileInputStream(java.io.FileInputStream)

Example 2 with ChannelProvider

use of com.google.api.gax.grpc.ChannelProvider in project google-cloud-java by GoogleCloudPlatform.

the class PublisherSnippets method createPublisherWithCustomCredentials.

private Publisher createPublisherWithCustomCredentials(TopicName topicName) throws Exception {
    // [START pubsub_publisher_custom_credentials]
    // read service account credentials from file
    CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(new FileInputStream("credentials.json")));
    ChannelProvider channelProvider = TopicAdminSettings.defaultChannelProviderBuilder().setCredentialsProvider(credentialsProvider).build();
    Publisher publisher = Publisher.defaultBuilder(topicName).setChannelProvider(channelProvider).build();
    // [END pubsub_publisher_custom_credentials]
    return publisher;
}
Also used : ChannelProvider(com.google.api.gax.grpc.ChannelProvider) FixedCredentialsProvider(com.google.api.gax.core.FixedCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) Publisher(com.google.cloud.pubsub.spi.v1.Publisher) FileInputStream(java.io.FileInputStream)

Aggregations

CredentialsProvider (com.google.api.gax.core.CredentialsProvider)2 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)2 ChannelProvider (com.google.api.gax.grpc.ChannelProvider)2 FileInputStream (java.io.FileInputStream)2 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)1 Subscriber (com.google.cloud.pubsub.spi.v1.Subscriber)1