Skip to content

Commit

Permalink
Fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbenckhuijsen committed Jan 3, 2025
1 parent a26e9dc commit ef4fc9a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Disposes;
import jakarta.enterprise.inject.Produces;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;

Expand Down Expand Up @@ -102,21 +100,6 @@ public SubscriptionAdminSettings subscriptionAdminSettings() throws IOException
return builder.build();
}

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

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

/**
* Creates a PubSub TopicAdminSettings using the configured project ID.
*/
Expand All @@ -127,21 +110,6 @@ public TopicAdminSettings topicAdminSettings() throws IOException {
return builder.build();
}

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

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

/**
* Creates a PubSub Topic if not already exist, using the configured project ID.
*/
Expand Down

0 comments on commit ef4fc9a

Please sign in to comment.