quarkiverse / quarkus-google-cloud-services

Google Cloud Services Quarkus Extensions
https://docs.quarkiverse.io/quarkus-google-cloud-services/main/index.html
Apache License 2.0
54 stars 34 forks source link

Feature: provide TransportChannelProvider as CDI bean? #555

Closed jfbenckhuijsen closed 3 months ago

jfbenckhuijsen commented 10 months ago

Hi,

As per https://docs.quarkiverse.io/quarkus-google-cloud-services/main/pubsub.html, we would need to provide a specific channel provider in case an emulator is used via the dev-service. Would it be an idea to provide the correct TransportChannelProvider as a CDI bean. Then the application logic can stay the same between production and emulator usage, and the toggle would just be based upon quarkus.google.cloud.pubsub.emulator-host having a value.

If it has no value, provide the default (see Publisher.Builder):

TopicAdminSettings.defaultGrpcTransportProviderBuilder().setChannelsPerCpu(1.0).build()

, otherwise

// Create a ChannelProvider that connects to the Dev Service
ManagedChannel channel = ManagedChannelBuilder.forTarget(emulatorHost).usePlaintext().build();
channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));

And have the user of the extension always use setChannelProvider().

If needed I can easily create a PR for this.

jfbenckhuijsen commented 10 months ago

Anyone able to respond to this?

loicmathieu commented 10 months ago

Sorry for not responding early.

I have somewhere a prototype to provide helper methods for PubSub to avoid too much boilerplate and handle this kind of stuff. I'll have a look next week wether I can finish it or not.

jfbenckhuijsen commented 10 months ago

Cool, if not, let me know. I have an app with quite some integration code which I’d happily see back in the extension instead of maintaining it myself. Or adapt that code to the stuff you’ve been working on.

loicmathieu commented 9 months ago

@jfbenckhuijsen see https://github.com/quarkiverse/quarkus-google-cloud-services/pull/577 it provides a QuarkusPubSub that allow passing an emulator host to work with a PubSub emulator.

It also provides convenience methods to creates topics, subscription, publisher, ...

Would it fixes your issue?

jfbenckhuijsen commented 9 months ago

Looks like it would fix it, ill test it in my code

jfbenckhuijsen commented 8 months ago

Just saw one use case which isn't handled: creating a Publisher for a topic in a different project. Ill create a PR for that

jfbenckhuijsen commented 8 months ago

604

jfbenckhuijsen commented 3 months ago

PR merged, closing as done