You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another edge case! As part of our applications, we use netflix-archaius for dynamic configuration at runtime - in this case, to control whether a queue listener is enabled or not, and to change if needed.
To do this, I have extended the DefaultMessageListenerContainerCoordinator to accept a small properties holder class that is used to determine the value of isAutoStartup, and add callbacks to properties to call start|stopContainer(identifier) to try and match the pattern used for creating other containers etc -
interfaceMessageListenerContainerCoordinatorProperties {
/** * @return Whether the {@link MessageListenerContainerCoordinator}'s {@link MessageListenerContainerCoordinator#startAllContainers()} will be invoked by Spring. */booleanisAutoStartContainersEnabled();
}
@Value@Builder(toBuilder = true)
classDefaultMessageListenerContainerCoordinatorPropertiesimplementsMessageListenerContainerCoordinatorProperties {
BooleanisAutoStartContainersEnabled;
@OverridepublicbooleanisAutoStartContainersEnabled() {
returnisAutoStartContainersEnabled;
}
}
classExtendedDefaultMessageListenerContainerCoordinatorextendsDefaultMessageListenerContainerCoordinator {
privatefinalMessageListenerContainerCoordinatorPropertiesproperties;
publicExtendedDefaultMessageListenerContainerCoordinator(finalList<MessageListenerContainerFactory> factories, finalMessageListenerContainerCoordinatorPropertiesproperties) {
super(factories);
this.properties = properties;
}
// Used to get a list of all containers so we can build the property callbacks...publicCollection<String> getContainerIdentifiers() {
returngetContainers().stream()
.map(MessageListenerContainer::getIdentifier)
.collect(toUnmodifiableSet());
}
@OverridepublicbooleanisAutoStartup() {
returnproperties.isAutoStartContainersEnabled();
}
}
classMessageListenerContainerLifecycleControllerimplementsSmartLifecycle {
privatefinalDefaultMessageListenerContainerCoordinatorcoordinator;
privatefinalMap<String, DynamicBooleanProperty> containerEnabled;
publicMessageListenerContainerLifecycleController(finalDefaultMessageListenerContainerCoordinatorcoordinator) {
this.coordinator = coordinator;
/** * Create all the properties and callbacks for each container identifier returned from * {@link ExtendedDefaultMessageListenerContainerCoordinator#getContainerIdentifiers()} on each to invoke the * @{@link MessageListenerContainerCoordinator#startContainer(String)} or * @{@link MessageListenerContainerCoordinator#stopContainer(String)}} depending on the value... */this.containerEnabled = createContainerLifecycleCallbacks(coordinator);
}
@Overridepublicvoidstart() {
containerEnabled.forEach((identifier, enabled) -> {
if (enabled.getValue()) {
coordinator.startContainer(identifier);
}
});
}
@Overridepublicvoidstop() {
coordinator.stopAllContainers();
}
@OverridepublicbooleanisRunning() {}
}
Another tweak that would help is being able to return a collection of all identifiers if possible 😄 Currently I have these classes sitting under the same package as the original to access the getContainers() method - other than this the library does everything I needed and more, nice to get a consumer going with a few annotations!
If there is a better way to raise these let me know - technically this is not an issue or bug!
The text was updated successfully, but these errors were encountered:
Hi,
Another edge case! As part of our applications, we use netflix-archaius for dynamic configuration at runtime - in this case, to control whether a queue listener is enabled or not, and to change if needed.
To do this, I have extended the DefaultMessageListenerContainerCoordinator to accept a small properties holder class that is used to determine the value of
isAutoStartup
, and add callbacks to properties to callstart|stopContainer(identifier)
to try and match the pattern used for creating other containers etc -Another tweak that would help is being able to return a collection of all identifiers if possible 😄 Currently I have these classes sitting under the same package as the original to access the
getContainers()
method - other than this the library does everything I needed and more, nice to get a consumer going with a few annotations!If there is a better way to raise these let me know - technically this is not an issue or bug!
The text was updated successfully, but these errors were encountered: