Skip to content

Add unregisterListenerContainer to PulsarListenerEndpointRegistry - #1553

Open
dlwhdgus0810 wants to merge 1 commit into
spring-projects:mainfrom
dlwhdgus0810:gh-1552-unregister-listener
Open

dlwhdgus0810 wants to merge 1 commit into
spring-projects:mainfrom
dlwhdgus0810:gh-1552-unregister-listener

Conversation

@dlwhdgus0810

Copy link
Copy Markdown

PulsarListenerEndpointRegistry lets you register listener containers at runtime with registerListenerContainer(...), but there is no way to remove one again. When listeners are recreated dynamically (for example per tenant/namespace, as described in #1552), the old container stays in the registry even after it has been stopped and destroyed. Endpoint ids can't be reused, and the registry keeps growing.

This adds unregisterListenerContainer(String id) to GenericListenerEndpointRegistry, so PulsarListenerEndpointRegistry inherits it. It works like KafkaListenerEndpointRegistry#unregisterListenerContainer(String) in Spring for Apache Kafka:

  • It returns the removed container, or null if nothing was registered under that id.
  • It only removes the container from the registry. It does not stop or destroy it, so the caller needs to do that before or after unregistering. The Javadoc says this explicitly.
  • It rejects an empty id, the same way getListenerContainer(String) does.

Example:

PulsarMessageListenerContainer container = registry.unregisterListenerContainer("my-listener");
if (container != null) {
    container.destroy();
}
registry.registerListenerContainer(newEndpoint, factory); // "my-listener" can be used again

I used @since 2.0.8 because main is on 2.0.8-SNAPSHOT (Spring Kafka also added this method in a patch release, 2.8.9). I can change it if this should go into a later version. I didn't add a What's New entry because that page is organized by minor release, but I can add one if you want.

Testing

New PulsarListenerEndpointRegistryTests checks that:

  • unregistering returns the container and removes it without stopping or destroying it
  • an unknown id returns null
  • the same id can be registered again afterwards

Commands:

  • ./gradlew :spring-pulsar:test --tests 'org.springframework.pulsar.config.*' passes, including the 3 new tests.
  • ./gradlew :spring-pulsar:checkstyleMain :spring-pulsar:checkstyleTest :spring-pulsar:javadoc passes.
  • If the method is changed so it doesn't remove the container, the removal test and the id-reuse test both fail.

Resolves #1552

PulsarListenerEndpointRegistry supports registering listener containers
at runtime via registerListenerContainer, but offers no way to remove
them. Applications that recreate listeners dynamically therefore cannot
reuse endpoint ids, and the registry keeps growing with stale
containers.

Add GenericListenerEndpointRegistry#unregisterListenerContainer(String),
mirroring KafkaListenerEndpointRegistry in Spring for Apache Kafka. The
method only removes the container from the registry and returns it; it
does not stop or destroy the container, which remains the caller's
responsibility.

Resolves spring-projects#1552

Signed-off-by: Hyun Lee <dlwhdugs4147@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unregisterListenerContainer(String id) to PulsarListenerEndpointRegistry

1 participant