Multiple binder configuration

soniya
soniya Member Posts: 23

Hi Team,

I am trying to connect to solace using spring cloud stream solace binder with all the properties in application.yaml

I have 1 producer on Aws service and another one in azure service in solace and I have a consumer at my local, how I can deifne multiple binder for same confumer in spring Yaml file.

Please suggest.

Comments

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 959 admin
    edited July 2022 #2

    Hi @soniya,

    Definitely possible! Let me first ask - are the brokers all connected as an event mesh? If so, then you could just have one binder connected to your local and let all the messages you're interested in by routed to that broker via dynamic message routing (DMR)

    If the brokers are not setup as an event mesh using DMR then to do this you would just need to define multiple binders: one for the AWS service, and one for the Azure service and then assign each binding the binder that you want it to use.

    It would look something like this:

    spring:
      cloud:
        stream:
          bindings:
            myFun1-in-0:
    	  destination: 'pub/sub/plus/>'
    	  binder: azure-solace
    	myFun2-out-0:
    	  destination: 'pub/sub/plus/>'
    	  binder: aws-solace
          binders:
            azure-solace:
              type: solace
              environment:
                solace:
                  java:
                    host: tcp://myazurehost:55555
                    msgVpn: azurevpn 
                    clientUsername: username 
                    clientPassword: password 
            aws-solace:
              type: solace
              environment:
                solace:
                  java:
                    host: tcp://myawshost:55555
                    msgVpn: awsvpn 
                    clientUsername: username 
                    clientPassword: password 
    
    


    Hope that helps!

  • soniya
    soniya Member Posts: 23
    edited July 2022 #3

    @marc Thanks for prompt response.

    I defined as you suggest but I am getting error as shown below.


    org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is java.lang.IllegalStateException: A default binder has been requested, but there is more than one binder available for 'org.springframework.cloud.stream.messaging.DirectWithAttributesChannel' : azure-solace,aws-solace, and no default binder has been set.



    I have also attached the below yaml file as well

    spring:

     cloud:

      function:

       definition: eSupplyOrderEventTypeNetwork1Consumer

      stream:

       bindings:

        eSupplyOrderEventTypeNetwork1Consumer-in-0:

         destination: E/Supply/Order/Update/SAPONESweden/Telia

         binder: aws-solace

        eSupplyOrderEventTypeNetwork1Consumer1-in-0:

         destination: E/Supply/Order/Update/SAPONEUS/Telia

         binder: azure-solace  

       binders:

        azure-solace:

         type: solace

         environment:

          solace:

           java:

            host: 'tcps://mr-60wcxjs67o9.messaging.solace.cloud:55443'

            msgVpn: azure-service

            clientUsername: solace-cloud-client

            clientPassword: ck2c98al0hdmpscsf9gbbto9fk

        aws-solace:

         type: solace

         environment:

          solace:

           java:

            host: 'tcps://mr9ax1hfmku30.messaging.solace.cloud:55443'

            msgVpn: solace-service

            clientUsername: solace-cloud-client

            clientPassword: b3blijh5s9dphg1m7bi6g8ao5f

    Please suggest..

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 959 admin

    Hi @soniya,

    Interesting - you didn't used to need to specify a default binder if each binding had a binder specified but maybe they changed that.

    Can you make sure that binders is located under spring.cloud.stream in the config? it's hard to tell if you have it under cloud or stream without the code formatting in your post. It should be at the same level as bindings .

    Here is an example in the official spring cloud stream samples as well: https://github.com/spring-cloud/spring-cloud-stream-samples/blob/main/multi-binder-samples/multi-binder-two-kafka-clusters/src/main/resources/application.yml

    If uses Kafka, but same idea with solace :)


    Hope that helps

  • soniya
    soniya Member Posts: 23

    I have attached the yaml file, I tried it without the default binder but I am getting same error when I am trying to run the application.


    main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is java.lang.IllegalStateException: A default binder has been requested, but there is more than one binder available for 



    Pls suggest.

  • soniya
    soniya Member Posts: 23

    Big thanks @marc , I used default binder and Its working now.