com.google.api.gax.rpc.FixedTransportChannelProvider Java Examples
The following examples show how to use
com.google.api.gax.rpc.FixedTransportChannelProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseIT.java From kafka-pubsub-emulator with Apache License 2.0 | 6 votes |
public static TransportChannelProvider getChannelProvider() { ManagedChannel channel = null; if (USE_SSL) { try { channel = NettyChannelBuilder.forAddress(LOCALHOST, PORT) .maxInboundMessageSize(100000) .sslContext( GrpcSslContexts.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE) .build()) .overrideAuthority(LOCALHOST + ":" + PORT) .build(); } catch (SSLException e) { fail("Unable to create SSL channel " + e.getMessage()); } } else { channel = ManagedChannelBuilder.forAddress(LOCALHOST, PORT).usePlaintext(true).build(); } return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); }
Example #2
Source File: TopicAdmin.java From ffwd with Apache License 2.0 | 6 votes |
@Provides @Singleton public TopicAdminClient getClient() throws IOException { final TopicAdminSettings.Builder adminSetting = TopicAdminSettings.newBuilder(); final String emulatorHost = System.getenv("PUBSUB_EMULATOR_HOST"); if (emulatorHost != null) { ManagedChannel channel = ManagedChannelBuilder.forTarget(emulatorHost).usePlaintext().build(); TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); adminSetting.setTransportChannelProvider(channelProvider); adminSetting.setCredentialsProvider(NoCredentialsProvider.create()); } return TopicAdminClient.create(adminSetting.build()); }
Example #3
Source File: PubSubSink.java From flink with Apache License 2.0 | 6 votes |
@Override public void open(Configuration configuration) throws Exception { serializationSchema.open(() -> getRuntimeContext().getMetricGroup().addGroup("user")); Publisher.Builder builder = Publisher .newBuilder(ProjectTopicName.of(projectName, topicName)) .setCredentialsProvider(FixedCredentialsProvider.create(credentials)); if (hostAndPortForEmulator != null) { managedChannel = ManagedChannelBuilder .forTarget(hostAndPortForEmulator) .usePlaintext(true) // This is 'Ok' because this is ONLY used for testing. .build(); channel = GrpcTransportChannel.newBuilder().setManagedChannel(managedChannel).build(); builder.setChannelProvider(FixedTransportChannelProvider.create(channel)) .setCredentialsProvider(NoCredentialsProvider.create()); } publisher = builder.build(); isRunning = true; }
Example #4
Source File: PubSubSink.java From flink with Apache License 2.0 | 5 votes |
@Override public void open(Configuration configuration) throws Exception { Publisher.Builder builder = Publisher .newBuilder(ProjectTopicName.of(projectName, topicName)) .setCredentialsProvider(FixedCredentialsProvider.create(credentials)); if (hostAndPortForEmulator != null) { managedChannel = ManagedChannelBuilder .forTarget(hostAndPortForEmulator) .usePlaintext(true) // This is 'Ok' because this is ONLY used for testing. .build(); channel = GrpcTransportChannel.newBuilder().setManagedChannel(managedChannel).build(); builder.setChannelProvider(FixedTransportChannelProvider.create(channel)) .setCredentialsProvider(NoCredentialsProvider.create()); } publisher = builder.build(); isRunning = true; }
Example #5
Source File: GCloudUnitTestBase.java From flink with Apache License 2.0 | 5 votes |
public static PubsubHelper getPubsubHelper() { if (channel == null) { //noinspection deprecation channel = ManagedChannelBuilder .forTarget(getPubSubHostPort()) .usePlaintext(true) .build(); channelProvider = FixedTransportChannelProvider .create(GrpcTransportChannel.create(channel)); } return new PubsubHelper(channelProvider); }
Example #6
Source File: PubSubManager.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
private static Optional<TransportChannelProvider> buildTransportChannelProvider(final PubSubConfig config) { if (config.isMockPubSubTopics()) { final ManagedChannel channel = buildChannel(config); return Optional.of(FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel))); } return Optional.empty(); }
Example #7
Source File: GcpPubSubEmulatorAutoConfiguration.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public TransportChannelProvider transportChannelProvider(GcpPubSubProperties gcpPubSubProperties) { ManagedChannel channel = ManagedChannelBuilder .forTarget("dns:///" + gcpPubSubProperties.getEmulatorHost()) .usePlaintext() .build(); return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); }
Example #8
Source File: GcpPubSubEmulatorAutoConfigurationTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testEmulatorConfig() { this.contextRunner.run((context) -> { CredentialsProvider defaultCredentialsProvider = context.getBean(CredentialsProvider.class); assertThat(defaultCredentialsProvider).isNotInstanceOf(NoCredentialsProvider.class); TopicAdminSettings topicAdminSettings = context.getBean(TopicAdminSettings.class); CredentialsProvider credentialsProvider = topicAdminSettings.getCredentialsProvider(); assertThat(credentialsProvider).isInstanceOf(NoCredentialsProvider.class); TransportChannelProvider transportChannelProvider = context.getBean(TransportChannelProvider.class); assertThat(transportChannelProvider).isInstanceOf(FixedTransportChannelProvider.class); }); }
Example #9
Source File: Connection.java From heroic with Apache License 2.0 | 5 votes |
void setEmulatorOptions(Optional<String> configuredEndpoint) { String endpoint = configuredEndpoint.orElse(System.getenv("PUBSUB_EMULATOR_HOST")); if (endpoint == null) { return; } log.info("PubSub emulator detected at {}", endpoint); ManagedChannel channel = ManagedChannelBuilder.forTarget(endpoint).usePlaintext().build(); channelProvider = FixedTransportChannelProvider.create( GrpcTransportChannel.create(channel)); credentialsProvider = NoCredentialsProvider.create(); }
Example #10
Source File: GCloudUnitTestBase.java From flink with Apache License 2.0 | 5 votes |
public static PubsubHelper getPubsubHelper() { if (channel == null) { //noinspection deprecation channel = ManagedChannelBuilder .forTarget(getPubSubHostPort()) .usePlaintext(true) .build(); channelProvider = FixedTransportChannelProvider .create(GrpcTransportChannel.create(channel)); } return new PubsubHelper(channelProvider); }
Example #11
Source File: UsePubSubEmulatorSnippet.java From google-cloud-java with Apache License 2.0 | 5 votes |
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] }
Example #12
Source File: GoogleCloudPubSubSinkConfiguration.java From divolte-collector with Apache License 2.0 | 5 votes |
private SinkFactory createFlushingPool(final RetrySettings retrySettings, final BatchingSettings batchingSettings, final String hostPort) { // Based on Google's PubSub documentation: // https://cloud.google.com/pubsub/docs/emulator#pubsub-emulator-java // What's going on here? Well… // - Authentication is disabled; the emulator doesn't use or support it. // - When Pub/Sub wants an I/O channel to talk to its Google Cloud endpoint, we're substituting our // own endpoint instead. This channel also has TLS disabled, because the emulator doesn't need, use // or support it. // return (vc, sinkName, registry) -> { logger.info("Configuring sink to use Google Cloud Pub/Sub emulator: {}", sinkName, hostPort); final String projectId = vc.configuration().global.gcps.projectId.orElseThrow(IllegalStateException::new); final ProjectTopicName topicName = ProjectTopicName.of(projectId, topic); final ManagedChannel channel = ManagedChannelBuilder.forTarget(hostPort).usePlaintext().build(); final TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); // There's no easy way to create topics for the emulator, so we create the topic ourselves. createTopic(hostPort, channelProvider, topicName); final Publisher.Builder builder = Publisher.newBuilder(topicName) .setRetrySettings(retrySettings) .setBatchingSettings(batchingSettings) .setChannelProvider(channelProvider) .setCredentialsProvider(NoCredentialsProvider.create()); final Publisher publisher = IOExceptions.wrap(builder::build).get(); return new GoogleCloudPubSubFlushingPool(sinkName, vc.configuration().global.gcps.threads, vc.configuration().global.gcps.bufferSize, publisher, Optional.of(channel), registry.getSchemaBySinkName(sinkName)); }; }
Example #13
Source File: PerformanceBenchmark.java From kafka-pubsub-emulator with Apache License 2.0 | 4 votes |
private TransportChannelProvider getChannelProvider() { ManagedChannel channel = ManagedChannelBuilder.forTarget(emulator).usePlaintext(true).build(); return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); }
Example #14
Source File: Demo.java From kafka-pubsub-emulator with Apache License 2.0 | 4 votes |
private TransportChannelProvider getChannelProvider() { ManagedChannel channel = ManagedChannelBuilder.forTarget(target).usePlaintext(true).build(); return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); }
Example #15
Source File: PubSubTestBinder.java From spring-cloud-gcp with Apache License 2.0 | 4 votes |
public PubSubTestBinder(String host) { GcpProjectIdProvider projectIdProvider = () -> "porto sentido"; // Transport channel provider so that test binder talks to emulator. ManagedChannel channel = ManagedChannelBuilder .forTarget(host) .usePlaintext() .build(); TransportChannelProvider transportChannelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); PubSubChannelProvisioner pubSubChannelProvisioner; try { SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create( SubscriptionAdminSettings.newBuilder() .setTransportChannelProvider(transportChannelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build() ); TopicAdminClient topicAdminClient = TopicAdminClient.create( TopicAdminSettings.newBuilder() .setTransportChannelProvider(transportChannelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build() ); pubSubChannelProvisioner = new PubSubChannelProvisioner( new PubSubAdmin(projectIdProvider, topicAdminClient, subscriptionAdminClient) ); } catch (IOException ioe) { throw new RuntimeException("Couldn't build test binder.", ioe); } DefaultSubscriberFactory subscriberFactory = new DefaultSubscriberFactory(projectIdProvider); subscriberFactory.setChannelProvider(transportChannelProvider); subscriberFactory.setCredentialsProvider(NoCredentialsProvider.create()); DefaultPublisherFactory publisherFactory = new DefaultPublisherFactory(projectIdProvider); publisherFactory.setChannelProvider(transportChannelProvider); publisherFactory.setCredentialsProvider(NoCredentialsProvider.create()); PubSubTemplate pubSubTemplate = new PubSubTemplate(publisherFactory, subscriberFactory); PubSubMessageChannelBinder binder = new PubSubMessageChannelBinder(null, pubSubChannelProvisioner, pubSubTemplate, new PubSubExtendedBindingProperties()); GenericApplicationContext context = new GenericApplicationContext(); binder.setApplicationContext(context); this.setBinder(binder); }
Example #16
Source File: EmulatorHelper.java From heroic with Apache License 2.0 | 4 votes |
private static TransportChannelProvider channelProvider(String endpoint) { ManagedChannel channel = ManagedChannelBuilder.forTarget(endpoint).usePlaintext().build(); return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); }