Source:
public Module module(final Key<PluginSink> key, final String id) { return new OutputPluginModule(id) { @Provides @Singleton public Publisher publisher() throws IOException { Preconditions.checkArgument(project.isPresent(), "Google project must be set in config"); Preconditions.checkArgument(topic.isPresent(), "Pubsub topic must be set in config"); final Duration publishDelayThreshold = Duration.ofNanos( publishDelayThresholdMs.orElse(DEFAULT_DELAY_THRESHOLD)); BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setElementCountThreshold(messageCountBatchSize) .setRequestByteThreshold(requestBytesThreshold) .setDelayThreshold(publishDelayThreshold) .build(); ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder() .setExecutorThreadCount(1).build(); final ProjectTopicName topicName = ProjectTopicName.of(project.get(), topic.get()); final Publisher.Builder publisher = Publisher.newBuilder(topicName) .setBatchingSettings(batchingSettings) .setExecutorProvider(executorProvider); if (serviceAccount.isPresent()) { CredentialsProvider credentials = FixedCredentialsProvider.create( ServiceAccountCredentials.fromStream(new FileInputStream(serviceAccount.get()))); publisher.setCredentialsProvider(credentials); } return publisher.build(); } @Override protected void configure() { if (serializer.isPresent()) { bind(Serializer.class).toInstance(serializer.get()); } else { bind(Serializer.class).to(Key.get(Serializer.class, Names.named("default"))); } final Key<PubsubPluginSink> sinkKey = Key.get(PubsubPluginSink.class, Names.named("pubsubSink")); bind(sinkKey).to(PubsubPluginSink.class).in(Scopes.SINGLETON); install(wrapPluginSink(sinkKey, key)); expose(key); } }; }

Target:
public Module module(final Key<PluginSink> key, final String id) { return new OutputPluginModule(id) { @Provides @Singleton public ProjectTopicName topicName() { Preconditions.checkArgument(project.isPresent(), "Google project must be set in config"); Preconditions.checkArgument(topic.isPresent(), "Pubsub topic must be set in config"); return ProjectTopicName.of(project.get(), topic.get()); } @Provides @Singleton public Publisher publisher() throws IOException { BatchingSettings batchingSettings = BatchingSettings.newBuilder() .setElementCountThreshold(messageCountBatchSize) .setRequestByteThreshold(requestBytesThreshold) .setDelayThreshold(publishDelayThreshold) .build(); ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder() .setExecutorThreadCount(1).build(); final Publisher.Builder publisher = Publisher.newBuilder(topicName()) .setBatchingSettings(batchingSettings) .setExecutorProvider(executorProvider); if (serviceAccount.isPresent()) { CredentialsProvider credentials = FixedCredentialsProvider.create( ServiceAccountCredentials.fromStream(new FileInputStream(serviceAccount.get()))); publisher.setCredentialsProvider(credentials); } 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)); publisher.setChannelProvider(channelProvider); publisher.setCredentialsProvider(NoCredentialsProvider.create()); } return publisher.build(); } @Override protected void configure() { if (serializer.isPresent()) { bind(Serializer.class).toInstance(serializer.get()); } else { bind(Serializer.class).to(Key.get(Serializer.class, Names.named("default"))); } final Key<PubsubPluginSink> sinkKey = Key.get(PubsubPluginSink.class, Names.named("pubsubSink")); bind(sinkKey).to(PubsubPluginSink.class).in(Scopes.SINGLETON); install(wrapPluginSink(sinkKey, key)); expose(key); } }; }