Add convenient StreamListenerContainer.getStreamName()

It would be nice to have `StreamListenerContainer.getStreamName()` method to fulfill need to dynamically stop/start listeners in reaction of broker events.

Let's say I need to react to RabbitMQ broker events of queue.created / queue.deleted and I need to start and stop listeners, which are assigned to these streams.
Currently I need to create an extra map of `listenerId` to `streamName` OR include `streamName` in `listenerId` (e.g. `listener:{streamName}`) to be able to carry our operations on listener.

A simple getter for `streamName` on the `StreamListenerContainer` would allow me to react to these changes dynamically without extra code effort.

Signed-off-by: David Horak <horak.david@protonmail.com>

[artem.bilan@broadcom.com: Fix JavaDoc for a new method. Fix Commit message]

Fixes: #2961

Signed-off-by: Artem Bilan <artem.bilan@broadcom.com>
# Conflicts:
#	spring-rabbit-stream/src/main/java/org/springframework/rabbit/stream/listener/StreamListenerContainer.java
This commit is contained in:
David Horak
2025-02-10 21:46:00 +01:00
committed by Artem Bilan
parent bbc23c336a
commit df5186c2b9

View File

@@ -56,6 +56,9 @@ import org.springframework.util.Assert;
* @author Gary Russell
* @author Christian Tzolov
* @author Ngoc Nhan
* @author Artem Bilan
* @author David Horak
*
* @since 2.4
*
*/
@@ -111,6 +114,15 @@ public class StreamListenerContainer extends ObservableListenerContainer {
this.streamConverter = new DefaultStreamMessageConverter(codec);
}
/**
* Get a stream name this listener is subscribed to.
* @return the stream name this listener is subscribed to.
* @since 3.2.3
*/
public String getStreamName() {
return this.streamName;
}
/**
* {@inheritDoc}
* Mutually exclusive with {@link #superStream(String, String)}.