Bukharov Sergey
Bukharov Sergey

Reputation: 10185

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.

Upvotes: 0

Views: 1172

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

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 {

Upvotes: 3

Related Questions