use of com.google.api.gax.core.CredentialsProvider 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.core.CredentialsProvider 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;
}
use of com.google.api.gax.core.CredentialsProvider in project spring-cloud-gcp by spring-cloud.
the class GcpPubSubEmulatorConfigurationTests method testEmulatorConfig.
@Test
public void testEmulatorConfig() {
this.contextRunner.run(context -> {
CredentialsProvider credentialsProvider = context.getBean(CredentialsProvider.class);
Assert.assertTrue("CredentialsProvider is not correct", credentialsProvider instanceof NoCredentialsProvider);
TransportChannelProvider transportChannelProvider = context.getBean(TransportChannelProvider.class);
Assert.assertTrue("TransportChannelProvider is not correct", transportChannelProvider instanceof FixedTransportChannelProvider);
});
}
use of com.google.api.gax.core.CredentialsProvider in project google-cloud-java by GoogleCloudPlatform.
the class UsePubSubEmulatorSnippet method main.
public static void main(String... args) throws IOException {
// [START pubsub_use_emulator]
String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build();
try {
TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
CredentialsProvider credentialsProvider = NoCredentialsProvider.create();
// Set the channel and credentials provider when creating a `TopicAdminClient`.
// Similarly for SubscriptionAdminClient
TopicAdminClient topicClient = TopicAdminClient.create(TopicAdminSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build());
TopicName topicName = TopicName.of("my-project-id", "my-topic-id");
// Set the channel and credentials provider when creating a `Publisher`.
// Similarly for Subscriber
Publisher publisher = Publisher.newBuilder(topicName).setChannelProvider(channelProvider).setCredentialsProvider(credentialsProvider).build();
} finally {
channel.shutdown();
}
// [END pubsub_use_emulator]
}
Aggregations