Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus pub sub producers #728

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/modules/ROOT/pages/pubsub.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ public class PubSubResource {
}
----

== AdminClient beans

If you need to perform admin actions on PubSub, you can inject the `com.google.cloud.pubsub.v1.SubscriptionAdminClient` and
`com.google.cloud.pubsub.v1.TopicAdminClient` as CDI beans as shown in the example below. This is usefull if the basic
facilities offered by `io.quarkiverse.googlecloudservices.pubsub.QuarkusPubSub` are not sufficient:

[source, java]
----
@Inject
SubscriptionAdminClient subscriptionAdminClient;

@Inject
TopicAdminClient topicAdminClient;

public someMethod() {
var pushConfig = ...; // Create com.google.pubsub.v1.PushConfig
subscriptionAdminClient.createSubscription("subscription-name", "topic-name", pushConfig, 10 /* ACK deadline */);

var topics = topicAdminClient.listTopics("my-google-project");
}
----

== Dev Service

=== Configuring the Dev Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkiverse.googlecloudservices.pubsub.deployment;

import io.quarkiverse.googlecloudservices.pubsub.PubSubProducer;
import io.quarkiverse.googlecloudservices.pubsub.QuarkusPubSub;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -15,6 +16,6 @@ public FeatureBuildItem feature() {

@BuildStep
public AdditionalBeanBuildItem producer() {
return new AdditionalBeanBuildItem(QuarkusPubSub.class);
return new AdditionalBeanBuildItem(QuarkusPubSub.class, PubSubProducer.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.quarkiverse.googlecloudservices.pubsub;

import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
import com.google.cloud.pubsub.v1.TopicAdminClient;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;

import java.io.IOException;

/**
* Producer class for PubSub beans.
*/
public class PubSubProducer {

@Inject
QuarkusPubSub quarkusPubSub;

/**
* Makes the subscription admin client available as CDI bean
*/
@Produces
public SubscriptionAdminClient subscriptionAdminClient() throws IOException {
return SubscriptionAdminClient.create(quarkusPubSub.subscriptionAdminSettings());
}

/**
* CDI Dispose method for {@link #subscriptionAdminClient()}. Shouldn't be called directly
*/
public void shutdownSubscriptionAdminClient(@Disposes SubscriptionAdminClient subscriptionAdminClient) {
subscriptionAdminClient.close();
}

/**
* Makes the topic admin client available as a CDI bean
*/
@Produces
public TopicAdminClient topicAdminClient() throws IOException {
return TopicAdminClient.create(quarkusPubSub.topicAdminSettings());
}

/**
* CDI Dispose method for {@link #topicAdminClient()}. Shouldn't be called directly
*/
public void shutdownTopicAdminClient(@Disposes TopicAdminClient topicAdminClient) {
topicAdminClient.close();
}

}
Loading