GoogleCloudPlatform / GoogleCloudPlatform/spring-cloud-gcp

Allow for programmatic customization of the Subscriber.Builder in PubSub library

Open
#3,724 0 comments 4 reactions 0 assignees View on GitHub
priority: p2 type: enhancement
Dominant language
Java
Stars
551
Forks
349
Avg merge
1d 13h
Merged PRs (30d)
14

Description

**Description:**
While I was researching what capabilities exist for OpenTelemetry within the PubSub libraries in both the [spring-cloud-gcp-pubsub](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/tree/v6.1.1/spring-cloud-gcp-pubsub) module as well as the [googleapis/java-pubsub](https://github.com/googleapis/java-pubsub) repo, I discovered that support was recently added to both the `Publisher.Builder` and `Subscriber.Builder` classes that enables OpenTelemetry tracing support (see googleapis/java-pubsub#2086). Right now I'm only able to enable this option for on the `Publisher` via the [PublisherCustomizer.java](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/v6.1.1/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/core/publisher/PublisherCustomizer.java) class, however there is no equivalent `SubscriberCustomizer` for the `Subscriber.Builder`.

**Desired Result:**
I'd like to be able to define one or more `SubscriberCustomizer` beans that I could use to tweak the options on the the `Subscriber.Builder` before the `.build()` method is called. Ideally the behavior should work the same as how the [DefaultPublisherFactory.java](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/v6.1.1/spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/support/DefaultPublisherFactory.java#L184-L197) does with any defined `PublisherCustomizer` beans.

**Considered Alternatives:**
The only alternative I see at the moment is to implement a new `SubscriberFactory` that would allow me to tweak the Subscriber options before the `.build()` method.
Contrived example:
```java
public class CustomSubscriberFactory implements SubscriberFactory {
//Constructor, fields, and other methods omitted...
@Override
public Subscriber createSubscriber(String subscriptionName, MessageReceiver receiver) {
Subscriber.Builder subscriberBuilder = Subscriber.newBuilder(projectSubscriptionName, receiver);
//Re-implement all the other builder configuration options

//Set all the new options on the builder
subscriberBuilder.setSomeOtherOption(true);
subscriberBuilder.setFooOption("bar");

Subscriber subscriber = subscriberBuilder.build();
return subscriber;
}
}
```

**Versions:**
- Spring Boot: `3.4.4`
- Spring Cloud GCP: `6.1.1`

Contributor guide

Open the contributing guide

Research direction

Start with spring-cloud-gcp-pubsub/src/main/java/com/google/cloud/spring/pubsub/core/publisher/PublisherCustomizer.java and the customization flow in DefaultPublisherFactory.java. Trace how Subscriber.Builder is created and built, then provide equivalent SubscriberCustomizer behavior before build so subscriber options can be configured without implementing a new SubscriberFactory.

Written by the indexing model from the issue text.

Assessment

Tech stack
gcp, java, spring-boot
Domain
api, backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.