Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injected MessageListenerContainerRegistry error when spring.cloud.aws.sqs.enabled is false #869

Closed
LucioC opened this issue Aug 18, 2023 · 4 comments
Labels
component: sqs SQS integration related issue status: waiting-for-triage Team has not yet looked into this issue

Comments

@LucioC
Copy link

LucioC commented Aug 18, 2023

Hello everyone,
I'm not sure if this is a bug or more like a question on how to avoid.

I want to control the start and stop of containers based on feature flags, so I have a component with the MessageListenerContainerRegistry injected similar to what is on the documentation. I do something like this:

@Component
public class SQSControl {
  @Autowired
  MessageListenerContainerRegistry registry;
  
  public void updateSqsProcessing(boolean enabled) {
      if(enabled) {
        registry.getListenerContainers().forEach(container -> {
            container.start();
        });
      } else {
        registry.getListenerContainers().forEach(container -> {
            container.stop();
        });
      }
  }
}

Then I was testing to add the option 'spring.cloud.aws.sqs.enabled' as false in the properties file. When starting the spring application it throws an error:

Field registry in SQSControl required a bean of type 'io.awspring.cloud.sqs.listener.MessageListenerContainerRegistry' that could not be found.

It seems there is no definition of an implementation for the registry interface when it is disabled.
I guess leaving the containers stopped has the same final effect as leaving this option disabled for us (no sqs processing) but would be good to have this to not break if someone tries to use it.
Any way to avoid the exception or should just not use this configuration property?

@tomazfernandes
Copy link
Contributor

Hi @LucioC, thanks for bringing this up.

If you set spring.cloud.aws.sqs.enabled to false, auto configuration won't kick in and the Registry bean won't be instantiated.

You can set ContainerOptions#autoStartup to false in the MessageListenerContainerFactory if you want all containers from that factory to have this behavior.

Let me know if that works for you.

@tomazfernandes tomazfernandes added component: sqs SQS integration related issue status: waiting-for-triage Team has not yet looked into this issue labels Aug 24, 2023
@LucioC
Copy link
Author

LucioC commented Sep 6, 2023

Hi @tomazfernandes . Yes I have set the autoStartup to false, and was controlling start and stop of containers fine. The issue is that by having access to the registry it will break if someone tries to use the enabled flag.

It should have a different way to control containers and still be able to use this flag. Is there one?

@tomazfernandes
Copy link
Contributor

Hi @tomazfernandes . Yes I have set the autoStartup to false, and was controlling start and stop of containers fine. The issue is that by having access to the registry it will break if someone tries to use the enabled flag.

The enabled flag triggers all autoconfiguration for the SQS integration and I don't understand why it might be set to false and still be expected to work.

Anyway, if you want to not be affected by the flag, you can declare your own MessageListenerContainerRegistry bean and use that.

You'd also need to instantiate the SqsTemplate if you're using it, and @SqsListener annotations would not work.

@tomazfernandes
Copy link
Contributor

Closing due to inactivity, we can reopen if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue status: waiting-for-triage Team has not yet looked into this issue
Projects
None yet
Development

No branches or pull requests

2 participants