0

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.

Bukharov Sergey
  • 9,767
  • 5
  • 39
  • 54

1 Answers1

3

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 {
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks for response. If i have defined Interface with this Channels application will work. But i want to move channels information from code to configuration. – Bukharov Sergey Sep 19 '17 at 15:39
  • No, that isn't possible. The interface must be there any way. At least that is how I see that... – Artem Bilan Sep 19 '17 at 15:41
  • You may rely on the on the built-in `Source`, `Sink` and `Processor` though. – Artem Bilan Sep 19 '17 at 15:44
  • Consider to investigate samples: https://github.com/spring-cloud/spring-cloud-stream-samples – Artem Bilan Sep 19 '17 at 15:44
  • 1
    So, you don't have choice with the custom channels unless declare interface. That is how Framework works. That's all. The binding feature is definitely about binding element. And we have to let Framework to know to what object we are going to bind - `MessageChannel`, `Flux`, `KStream` etc.. – Artem Bilan Sep 19 '17 at 15:47
  • 1
    Yes, you are right. Interfaces is absolutely necessary here. No another way. Thanks. This config allow to configure channels in created beans. – Bukharov Sergey Sep 19 '17 at 16:02
  • Good to know we are in an agreement. Time to accept the answer to let other people to know that here is a good info! – Artem Bilan Sep 19 '17 at 16:04