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