0

I want to update an application that uses Spring Cloud stream with a deprecated annotations approach to functional style. I already use the legacy approach for classical RabbitMQ producer and consumer, but since in the Spring Cloud Stream 4.x annotation approach was removed I need to migrate to a functional model. According to documentation for send arbitrary data I can use StreamBridge but I also need to have advantages that provide Spring Cloud Stream provides for classical binder like: auto creation topic, producer configuration e.t.c. So again according to documentation I can use spring.cloud.stream.output-bindings property for pre-create an output binding at the initialization as a result I have configuration line in the example.

spring:
  cloud:
    stream:
       output-bindings: test
      bindings:
        test-out-0:
          contentType: application/json
      rabbit:
        bindings:
          test-out-0:
            producer:
              delivery-mode: non-persistent
              transacted: true

But this not works for me since I have come functional beans in some internal libraries which are found by FunctionCatalog.lookup method so pre-creation of topic will be skipped.

Spring Cloud Stream source code

P.S. spring.cloud.stream.function.autodetect and also doesn't work

Jungle
  • 107
  • 2
  • 11
  • 1
    Ia m not sure i understand the question. What exactly does not work for you? What does `StreamBridge` has to do with `FunctionCatalog.lookup`? The best thing you can do is create a small project and push it to Github somewhere so we can take a look – Oleg Zhurakousky May 31 '23 at 13:35
  • @OlegZhurakousky thanks for respond. createStandAloneBindingsIfNecessary from FunctionConfiguration that responsible bindingCreation(as I understand), have several checks, one of this check is sourceFunc existence that that is get by FunctionCatalog.lookup. so FunctionCatalog.lookup will find any random Suplier<> bean from the context and according to existing conditions, binding will be not create. Therefore binding does not exist and will be created after first StreamBridge usage – Jungle May 31 '23 at 15:08
  • @OlegZhurakousky I've added picture of spring source code what I am taking about – Jungle May 31 '23 at 15:16
  • 1
    I see the issue. Just fixed it - https://github.com/spring-cloud/spring-cloud-stream/commit/2ab71f2f320bad3ce7af6e059d205f8230ba1d08 It's a rare case since you have only one discoverable function. The next release is at the end of the month, but for now all you need to do is define another dummy function bean and you should be fine. – Oleg Zhurakousky May 31 '23 at 16:41
  • @OlegZhurakousky I found nice workaround better that dummy function spring.cloud.function.ineligible-definitions property do what I need – Jungle Jun 01 '23 at 05:21
  • @OlegZhurakousky May I wonder why we need this outputBindings.length == 1 check if I have several bindings it will not work any way – Jungle Jun 01 '23 at 05:34
  • Yeah, this is because if there are more then one function it will never get into the If statement since sourceFunction will be null. In other words the issue you are encountering is due to the feature that we have where if there is only one function in catalog it can be looked up by any name – Oleg Zhurakousky Jun 01 '23 at 09:03
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/253912/discussion-between-jungle-and-oleg-zhurakousky). – Jungle Jun 01 '23 at 11:35

0 Answers0