Search code examples
javaspringspring-bootspring-cloudspring-messaging

How to autowire spring stream cloud bindings


I defined error and notification bindings in application.yml

cloud:
  stream:
    bindings:
      error:
        destination: error
        binder: default
      notification:
        destination: notification
        binder: default

How can i get those beans in my components?

I tried this approach:

@Component
class MyComponent {

   @Autowired
   @Qualified("notification")
   MessageChannel notificationChannel;
}

But notificationChanel is not found.

Update cloud.stream.bindings.* allow only configure channels. But does not create it.


Solution

  • Are you sure that you have @EnableBinding and appropriate interface to declare @Input or @Output?

    https://docs.spring.io/spring-cloud-stream/docs/Chelsea.SR2/reference/htmlsingle/index.html#_declaring_and_binding_channels

    public interface Barista {
    
        @Input
        SubscribableChannel orders();
    
        @Output
        MessageChannel hotDrinks();
    
        @Output
        MessageChannel coldDrinks();
    }
    
    ...
    @EnableBinding(Barista.class)
    public class CafeConfiguration {