In Spring cloud , i would like to print logs which will tell to which queue application is connected

Monica Gavali
Monica Gavali Member Posts: 17
edited February 2022 in Connectors & Integrations #1

Hi,

I am working on spring-cloud-solace. In application i need logger to track which queue application is connected to. Could you pls help

Tagged:

Comments

  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 594 admin

    Hi there @Monica Gavali ..! So you definitely want something application-side, yes? I'm digging through the code for the binder (which you can find here: https://github.com/SolaceProducts/solace-spring-cloud/tree/master/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder-core/src/main/java/com/solace/spring/cloud/stream/binder) and I can't see an explicit "you are bound to this queue" log entry. There is this line here, when it actually tries to connect:

    logger.info(String.format("Binding flow receiver container %s", id));
    

    But it doesn't say the queue name. I also tried turning up the logging level of the underlying Solace JCSMP API to debug, and the only place I see the queue name echoed is when the createFlow() method is called, so you could try turning up your logging to debug for this class?:

    ~LOG DEBUG~ 11:09:44.372 [main] DEBUG com.solac.jcsmp.impl.RequestResponseTask - RequestResponseTask ([BRT resource=q_samples existingFH=null flowType=CONSUMER counter=0]) startTimer 
    

    (my queue is called "q_samples").

    Finally, and my preferred way (I think) of doing this: why not look at the broker event logs? It keeps track of everything, every app who binds to every queue:

    [/usr/sw/jail/logs]$ grep CLIENT_BIND event.log
    
    2021-09-30T15:07:45.719+00:00 <local3.notice> b0926f3edf53 event: CLIENT: CLIENT_CLIENT_BIND_SUCCESS: default AaronsThinkPad3/46840/#00110001/nBdZS0xMN5 Client (81) AaronsThinkPad3/46840/#00110001/nBdZS0xMN5 username default Bind to Durable Queue q_samples AccessType(Exclusive), Quota(5000MB), MaxMessageSize(10000000B), AllOthersPermission(Read|Consume), RespectTTL(No), RejectMsgToSenderOnDiscard(Yes), ReplayFrom(N/A), GrantedPermission(Read|Consume), FlowType(Consumer), FlowId(39), ForwardingMode(StoreAndForward), MaxRedelivery(0), TransactedSessionId(-1) completed
    2021-09-30T15:08:32.429+00:00 <local3.notice> b0926f3edf53 event: CLIENT: CLIENT_CLIENT_BIND_SUCCESS: default AaronsThinkPad3/39652/#00120001/--eNmhYLCl Client (80) AaronsThinkPad3/39652/#00120001/--eNmhYLCl username default Bind to Durable Queue q_samples AccessType(Exclusive), Quota(5000MB), MaxMessageSize(10000000B), AllOthersPermission(Read|Consume), RespectTTL(No), RejectMsgToSenderOnDiscard(Yes), ReplayFrom(N/A), GrantedPermission(Read|Consume), FlowType(Consumer), FlowId(40), ForwardingMode(StoreAndForward), MaxRedelivery(0), TransactedSessionId(-1) completed
    2021-09-30T15:09:34.735+00:00 <local3.notice> b0926f3edf53 event: CLIENT: CLIENT_CLIENT_BIND_SUCCESS: default AaronsThinkPad3/47492/#00120001/qdHjxZeD5x Client (84) AaronsThinkPad3/47492/#00120001/qdHjxZeD5x username default Bind to Durable Queue q_samples AccessType(Exclusive), Quota(5000MB), MaxMessageSize(10000000B), AllOthersPermission(Read|Consume), RespectTTL(No), RejectMsgToSenderOnDiscard(Yes), ReplayFrom(N/A), GrantedPermission(Read|Consume), FlowType(Consumer), FlowId(41), ForwardingMode(StoreAndForward), MaxRedelivery(0), TransactedSessionId(-1) completed
    
  • Monica Gavali
    Monica Gavali Member Posts: 17

    Hi Aron,
    Thanks for quick reply...
    Could you pls help me with how to get/set broker event logs in application.

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

    Hi @Monica Gavali,

    The Spring Cloud Stream binder actually already logs this for you. For example, running this app I see logs that look like below. You would most likely care about the logs from the SolaceQueueProvisioner class which state both the queue, but also the topic subscriptions applied to it.

    [2m2021-10-01 10:43:25.500[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.c.s.binder.DefaultBinderFactory     [0;39m [2m:[0;39m Creating binder: local-solace
    [2m2021-10-01 10:43:25.586[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36m.SolaceMessageChannelBinderConfiguration[0;39m [2m:[0;39m Connecting JCSMP session JCSMPSession
    [2m2021-10-01 10:43:25.613[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connecting to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (host 1 of 1, smfclient 1, attempt 1 of 1, this_host_attempt: 1 of 21)
    [2m2021-10-01 10:43:25.661[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.j.protocol.impl.TcpClientChannel    [0;39m [2m:[0;39m Connected to host 'orig=tcp://localhost:4444, scheme=tcp://, host=localhost, port=4444' (smfclient 1)
    [2m2021-10-01 10:43:25.712[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.c.s.binder.DefaultBinderFactory     [0;39m [2m:[0;39m Caching the binder: local-solace
    [2m2021-10-01 10:43:25.713[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.c.s.binder.DefaultBinderFactory     [0;39m [2m:[0;39m Retrieving cached binder: local-solace
    [2m2021-10-01 10:43:25.829[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.p.SolaceQueueProvisioner    [0;39m [2m:[0;39m Creating durable queue scst/wk/SINK/plain/TEMPS.Q for consumer group SINK
    [2m2021-10-01 10:43:25.887[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.p.SolaceQueueProvisioner    [0;39m [2m:[0;39m Testing consumer flow connection to queue scst/wk/SINK/plain/TEMPS.Q (will not start it)
    [2m2021-10-01 10:43:25.921[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.p.SolaceQueueProvisioner    [0;39m [2m:[0;39m Connected test consumer flow to queue scst/wk/SINK/plain/TEMPS.Q, closing it
    [2m2021-10-01 10:43:25.929[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.c.stream.binder.BinderErrorChannel  [0;39m [2m:[0;39m Channel 'TEMPS.Q.SINK.errors' has 1 subscriber(s).
    [2m2021-10-01 10:43:25.930[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.c.stream.binder.BinderErrorChannel  [0;39m [2m:[0;39m Channel 'TEMPS.Q.SINK.errors' has 2 subscriber(s).
    [2m2021-10-01 10:43:25.939[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating 5 consumer flows for queue scst/wk/SINK/plain/TEMPS.Q <inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8>
    [2m2021-10-01 10:43:25.940[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating consumer 1 of 5 for inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8
    [2m2021-10-01 10:43:25.942[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.util.FlowReceiverContainer  [0;39m [2m:[0;39m Binding flow receiver container a0b6c684-ce22-42b5-af51-120daf8a0365
    [2m2021-10-01 10:43:25.952[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating consumer 2 of 5 for inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8
    [2m2021-10-01 10:43:25.953[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.util.FlowReceiverContainer  [0;39m [2m:[0;39m Binding flow receiver container e9c9d1e3-ce21-4374-984c-1f1a667fa43a
    [2m2021-10-01 10:43:25.958[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating consumer 3 of 5 for inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8
    [2m2021-10-01 10:43:25.958[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.util.FlowReceiverContainer  [0;39m [2m:[0;39m Binding flow receiver container 83e30b7b-aee1-406a-9934-e82abcff36b9
    [2m2021-10-01 10:43:25.964[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating consumer 4 of 5 for inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8
    [2m2021-10-01 10:43:25.964[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.util.FlowReceiverContainer  [0;39m [2m:[0;39m Binding flow receiver container 4cbfa23c-3d4c-4d6e-960e-ed1fd53c7be2
    [2m2021-10-01 10:43:25.971[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m Creating consumer 5 of 5 for inbound adapter ab3c72d6-5cc0-4709-95b6-f78fa5b914c8
    [2m2021-10-01 10:43:25.971[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.util.FlowReceiverContainer  [0;39m [2m:[0;39m Binding flow receiver container 63e0311b-056a-40b4-bcc4-b67b591528f2
    [2m2021-10-01 10:43:26.003[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.p.SolaceQueueProvisioner    [0;39m [2m:[0;39m Subscribing queue scst/wk/SINK/plain/TEMPS.Q to topic sensor/temperature/>
    [2m2021-10-01 10:43:26.010[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.p.SolaceQueueProvisioner    [0;39m [2m:[0;39m Subscribing queue scst/wk/SINK/plain/TEMPS.Q to topic TEMPS.Q
    [2m2021-10-01 10:43:26.015[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.s.c.s.b.i.JCSMPInboundChannelAdapter[0;39m [2m:[0;39m started com.solace.spring.cloud.stream.binder.inbound.JCSMPInboundChannelAdapter@17a4cc34
    [2m2021-10-01 10:43:26.028[0;39m [32m INFO[0;39m [35m21681[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mc.s.samples.spring.scs.TemperatureSink  [0;39m [2m:[0;39m Started TemperatureSink in 3.075 seconds (JVM running for 3.818)
    

    Hope that helps!

  • Monica Gavali
    Monica Gavali Member Posts: 17

    Thanks Marcs !!!.
    I was using old solace dependency hence it was not printing the logs.
    Now using <spring-cloud.version>2020.0.4</spring-cloud.version> with it able to print queue connected logs.
    But new problem occurred .

    With old dependency solace was able to connect to queue named- GMMO.UCTRADE.DSLT01 .
    Below is property file :

    spring:
    cloud:
    stream:
    function:
    definition: functionUsingTargetDestHeader
    bindings:
    functionUsingTargetDestHeader-in-0:
    destination: GMMO.UCTRADE.DSLT01
    functionUsingTargetDestHeader-out-0:
    destination: default
    binders:
    local-solace:
    type: solace
    environment:
    solace:
    java:
    host: host
    msgVpn: vpn
    clientUsername: username
    clientPassword: pwd
    solace:
    bindings:
    functionUsingTargetDestHeader-in-0:
    consumer:
    provisionDurableQueue: true
    queueNamePrefix: ""
    useFamiliarityInQueueName: false
    useDestinationEncodingInQueueName: false
    useGroupNameInQueueName: false

    After newer version of dependency it is connecting to some random queue , below are logs :
    2021-10-04 11:55:56.774 INFO 21976 --- [ main] c.s.s.c.s.b.i.JCSMPInboundChannelAdapter : Creating consumer 1 of 1 for inbound adapter dba828dd-9fbc-4234-9bbf-06c7127eb054
    2021-10-04 11:55:56.777 INFO 21976 --- [ main] c.s.s.c.s.b.util.FlowReceiverContainer : Binding flow receiver container 7ba0199f-bc76-456f-9cb0-43c9a07e35fc
    2021-10-04 11:55:56.956 INFO 21976 --- [ main] c.s.s.c.s.b.p.SolaceQueueProvisioner : Subscribing queue #P2P/QTMP/v:gbwgdcsolacetest01/3e800d65-9488-4b2c-a7d5-27a3132b725c/GMMO.UCTRADE.DSLT01 to topic GMMO.UCTRADE.DSLT01

    Sharing pom.xml for reference :

    <?xml version="1.0" encoding="UTF-8"?>

    4.0.0

    org.springframework.boot
    spring-boot-starter-parent
    2.5.3


    com.poc
    consumer
    0.0.3-SNAPSHOT
    consumer
    Demo project for Spring Boot

    <java.version>1.8</java.version>
    <spring-cloud.version>2020.0.4</spring-cloud.version>
    <solace-spring-cloud-bom.version>2.1.0</solace-spring-cloud-bom.version>




    org.springframework.cloud
    spring-cloud-dependencies
    ${spring-cloud.version}
    pom
    import


    com.solace.spring.cloud
    solace-spring-cloud-bom
    2.1.0
    pom


    <dependencies>
        <dependency>
          <groupId>com.solace.spring.cloud</groupId>
          <artifactId>spring-cloud-starter-stream-solace</artifactId>
          <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <!-- Excluding logback dependencies to use l4j2 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.github.ulisesbocchio</groupId>
            <artifactId>jasypt-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>       
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    

  • Monica Gavali
    Monica Gavali Member Posts: 17

    Please ignore above comment.
    Able to print logs on console.
    Thanks Marc and Aaron .. :)

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

    Excellent, thanks for the update @Monica Gavali. Glad it worked for you!

This Week's Leaders