Announcement Announcement Module
Collapse
No announcement yet.
help on global channel interceptor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • help on global channel interceptor

    Hi all,

    I've defined some channels in order to handle my use case:

    1. a message-driven-channel-adapter for retrieving messages
    2. after a xpath-router channel is used to map to which channel the message shuld be routed, eg. C1 / C2
    3. each Ci is a stored-proc-outbound-channel-adapter for handling the message

    So I have below channels

    Code:
        <!-- Channels definition -->
        <int:channel id="jmsListenerInChannel"/>
        <int:channel id="bpListMessageTypeChannel"/>
        <int:channel id="personListMessageTypeChannel"/>
        <int:channel id="unmatchedMessageTypeChannel"/>
    The entire chain works but from logs "I don't see what channels have been called" so I would like to log e.g. that channels A,C,D etc have been called.
    So I tried to configure a global wire tap as a special case of the global channel interceptor:

    Code:
        <!-- Global Channel Interceptor -->
        <int:wire-tap pattern="*" order="-1" channel="logger"/>
        <int:logging-channel-adapter id="logger" expression="'Payload: '.concat(payload)" level="INFO"/>
    but I see twice a logging entry for the same channel ...
    In my use case an example of flow could be: jmsListenerInChannel --> bpListMessageTypeChannel so I would like to see 2 logging entries (for example the channel name), one logging entry for each channel ... but I see twice a logging entry for the jmsListenerInChannel ...

    I'm tryinng to find out where I'm wrong ...

    Thanks and regards
    nuvola

  • #2
    It's hard to say without seeing your configuration and log. Can you attach those?

    Comment


    • #3
      Below my configuration and an extract from logs

      Configuration
      Code:
      <beans:beans xmlns:xsi=...>
      
          <!-- Channels definition -->
          <int:channel id="jmsListenerChannel"/>
          <int:channel id="bpListMessageTypeChannel"/>
          <int:channel id="personListMessageTypeChannel"/>
          <int:channel id="unknownMessageTypeChannel"/>
      
          <!-- Global Channel Interceptor -->
          <int:wire-tap pattern="*" order="-1" channel="logger"/>
          <int:logging-channel-adapter id="logger" expression="'### my debugging ###'" level="INFO"/>
      
          <!-- Map of namespace prefix to URI -->
          <util:map id="messageNamespaceMap">...</util:map>
      
          <!-- Data source definition -->
          <beans:bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">...</beans:bean>
      
          <!-- The default error channel -->
          <stream:stderr-channel-adapter channel="errorChannel" append-newline="true" />
      
          <!-- A default JMS message listener -->
          <jms:message-driven-channel-adapter id="jmsMessageChannelAdapter"
                                              connection-factory="connectionFactory"
                                              destination="myQueue"
                                              channel="jmsListenerChannel"/>
      
          <!-- Message type routing -->
          <si-xml:xpath-router id="messageTypeRouter" input-channel="jmsListenerChannel" resolution-required="false" default-output-channel="unmatchedMessageTypeChannel">
              <si-xml:xpath-expression expression="/messageNs:message/messageNs:header/messageNs:applicationMessageType/text()" namespace-map="messageNamespaceMap"/>
              <si-xml:mapping value="bp_list" channel="bpListMessageTypeChannel"/>
              <si-xml:mapping value="person_list" channel="personListMessageTypeChannel"/>
          </si-xml:xpath-router>
      
          <!--  Dispatch message -->
          <file:outbound-channel-adapter id="unmatchedMessageTypeChannel" directory="file:${unmatchedMessageType.directory}"
             filename-generator-expression="'${queue.jndi.name}' + '_' + headers['jms_messageId'].replace('&lt;','').replace('&gt;','').replace(':','_') + '_' + new java.text.SimpleDateFormat('ddMMyyyy_HHmmss').format(new java.util.Date()) + '.xml'"/>
      
          <int-jdbc:stored-proc-outbound-channel-adapter channel="bpListMessageTypeChannel"
                                                         data-source="dataSource"
                                                         stored-procedure-name="USER_CREATOR.PKG_WRITE.PROCESS_BP"
                                                         auto-startup="true"
                                                         ignore-column-meta-data="true">
      ...
          </int-jdbc:stored-proc-outbound-channel-adapter>
      
          <int-jdbc:stored-proc-outbound-channel-adapter channel="personListMessageTypeChannel"
                                                         data-source="dataSource"
                                                         stored-procedure-name="USER_CREATOR.PKG_WRITE.PROCESS_PERS"
                                                         auto-startup="true"
                                                         ignore-column-meta-data="true">
      ...
          </int-jdbc:stored-proc-outbound-channel-adapter>
      
          <!-- JMS stuff resolution -->
          <jee:jndi-lookup id="connectionFactory" jndi-name="${connection.factory.jndi.name}">...</jee:jndi-lookup>
          <jee:jndi-lookup id="myQueue" jndi-name="${queue.jndi.name}">...</jee:jndi-lookup>
      
      </beans:beans>
      Logs
      Code:
      Running ch.tmp.integration.jms.JMSListenerTest
      29.apr.2012 13:21:23,023 - (LISTENER) (main) [INFO  ]-[DefaultConfiguringBeanFactoryPostProcessor(120 )] - No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
      29.apr.2012 13:21:23,026 - (LISTENER) (main) [INFO  ]-[DefaultConfiguringBeanFactoryPostProcessor(146 )] - No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
      29.apr.2012 13:21:24,109 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {logging-channel-adapter:logger.adapter} as a subscriber to the 'logger' channel
      29.apr.2012 13:21:24,109 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'logger' has 1 subscriber(s).
      29.apr.2012 13:21:24,110 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started logger.adapter
      29.apr.2012 13:21:24,110 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {message-handler} as a subscriber to the 'errorChannel' channel
      29.apr.2012 13:21:24,110 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'errorChannel' has 1 subscriber(s).
      29.apr.2012 13:21:24,111 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started org.springframework.integration.config.ConsumerEndpointFactoryBean#0
      29.apr.2012 13:21:24,111 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {xml:xpath-router:messageTypeRouter} as a subscriber to the 'jmsListenerChannel'channel
      29.apr.2012 13:21:24,112 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'jmsListenerChannel' has 1 subscriber(s).
      29.apr.2012 13:21:24,112 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started messageTypeRouter
      29.apr.2012 13:21:24,112 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {message-handler:unmatchedMessageTypeChannel.adapter} as a subscriber to the 'unmatchedMessageTypeChannel' channel
      29.apr.2012 13:21:24,113 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'unmatchedMessageTypeChannel' has 1 subscriber(s).
      29.apr.2012 13:21:24,113 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started unmatchedMessageTypeChannel.adapter
      29.apr.2012 13:21:24,113 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {message-handler} as a subscriber to the 'bpListMessageTypeChannel' channel
      29.apr.2012 13:21:24,114 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'bpListMessageTypeChannel' has 1 subscriber(s).
      29.apr.2012 13:21:24,115 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started org.springframework.integration.config.ConsumerEndpointFactoryBean#1
      29.apr.2012 13:21:24,115 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {message-handler} as a subscriber to the 'personListMessageTypeChannel' channel
      29.apr.2012 13:21:24,116 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'personListMessageTypeChannel' has 1 subscriber(s).
      29.apr.2012 13:21:24,116 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started org.springframework.integration.config.ConsumerEndpointFactoryBean#2
      29.apr.2012 13:21:24,117 - (LISTENER) (main) [INFO  ]-[EventDrivenConsumer                (75  )] - Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
      29.apr.2012 13:21:24,117 - (LISTENER) (main) [INFO  ]-[AbstractSubscribableChannel        (46  )] - Channel 'errorChannel' has 2 subscriber(s).
      29.apr.2012 13:21:24,117 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started _org.springframework.integration.errorLogger
      29.apr.2012 13:21:24,118 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate@16c2c0
      29.apr.2012 13:21:24,239 - (LISTENER) (main) [INFO  ]-[AbstractEndpoint                   (87  )] - started jmsMessageChannelAdapter
      29.apr.2012 13:21:24,255 - (LISTENER) (main) [INFO  ]-[JMSListenerTest                    (26  )] - Ready to retrieve messages ...
      29.apr.2012 13:21:24,292 - (LISTENER) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingHandler                     (136 )] - ### my debugging ###
      29.apr.2012 13:21:24,303 - (LISTENER) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingHandler                     (136 )] - ### my debugging ###
      29.apr.2012 13:21:29,274 - (LISTENER) (Thread-3) [INFO  ]-[AbstractEndpoint                   (103 )] - stopped org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate@16c2c0
      29.apr.2012 13:21:29,274 - (LISTENER) (Thread-3) [INFO  ]-[AbstractEndpoint                   (103 )] - stopped jmsMessageChannelAdapter
      29.apr.2012 13:21:29,275 - (LISTENER) (Thread-3) [INFO  ]-[EventDrivenConsumer                (75  )] - Removing {logging-channel-adapter:logger.adapter} as a subscriber to the 'logger' channel
      ...
      The flow is:
      1. jmsListenerChannel channel -> retrieve messages
      2. xpath-router routes for example to bpListMessageTypeChannel channel

      As said I would like to see one "### my debugging ###" entry for each triggered channel but from logs I see twice:

      Code:
      29.apr.2012 13:21:24,292 - (LISTENER) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingHandler                     (136 )] - ### my debugging ###
      29.apr.2012 13:21:24,303 - (LISTENER) (org.springframework.jms.listener.DefaultMessageListenerContainer#0-1) [INFO  ]-[LoggingHandler                     (136 )] - ### my debugging ###
      so I can deduce that jmsListenerChannel has been triggered but I don't see anything for bpListMessageTypeChannel ...

      An additional question, how could I get the channel name ? So I can replace

      <int:logging-channel-adapter id="logger" expression="'### my debugging ###'" level="INFO"/>

      with

      <int:logging-channel-adapter id="logger" expression="'Triggered channel:' + ??? channel.name ??? " level="INFO"/>


      Thanks and regards
      nuvola

      Comment


      • #4
        The output above is what you would expect to see. org.springframework.jms.listener.DefaultMessageLis tenerContainer#0-1 is the thread Id.

        Try enabling DEBUG for org.springframework.integration and remove your logging-channel-adapter. You will see all messages going across all channels including the channel name.

        If you need more than that, you can write your own ChannelInterceptor using ChannelInterceptorAdapter. Override preSend which passes the channel as a parameter from which you can get the channel name and generate a log message.

        Comment


        • #5
          Thanks for the hint.

          I enabled DEBUG for org.springframework.integration and I see the payload for each triggered channel in preSend & postSend methods and also the channel name.
          The message could contain sensitive data so we are not allowed to trace that payload in the log file, instead it would be nice to trace the channel name at least :-)

          Is there a way to get the channel name in my expression="..." ?
          I'm trying how to find out that ... without writing our own ChannelInterceptor only for getting the channel name ...

          Thanks and regards
          nuvola

          Comment


          • #6
            Hi,

            I didn't find out how to get the channel name in my expression="..." so I added in each channel an interceptors def:

            Code:
                <!-- Channels definition -->
                <int:channel id="jmsListenerChannel">
                  <int:interceptors>
                    <int:wire-tap channel="jmsListenerChannel-logger"/>
                  </int:interceptors>
                </int:channel>
            
                <int:channel id="bpListMessageTypeChannel">
                    <int:interceptors>
                      <int:wire-tap channel="bpListMessageTypeChannel-logger"/>
                    </int:interceptors>
                </int:channel>
            
                <int:channel id="personListMessageTypeChannel">
                  <int:interceptors>
                    <int:wire-tap channel="personListMessageTypeChannel-logger"/>
                  </int:interceptors>
                </int:channel>
            
                <int:channel id="unmatchedMessageTypeChannel">
                  <int:interceptors>
                    <int:wire-tap channel="unmatchedMessageTypeChannel-logger"/>
                  </int:interceptors>
                </int:channel>
            
                <int:logging-channel-adapter id="jmsListenerChannel-logger"   expression="'### JMS Listener Channel ### '    + headers" level="INFO"/>
                <int:logging-channel-adapter id="bpListMessageTypeChannel-logger"     expression="'### BP List Message Type Channel ### '" level="INFO"/>
                <int:logging-channel-adapter id="personListMessageTypeChannel-logger" expression="'### Person List Message Type Channel ### '" level="INFO"/>
                <int:logging-channel-adapter id="unmatchedMessageTypeChannel-logger"  expression="'### Unmatched Message Type Channel ### '" level="INFO"/>
            Instead of defining a global one:

            Code:
                <!-- Global Channel Interceptor -->
                <int:logging-channel-adapter id="logger" expression="... how to get channel.name ??? ..." level="INFO"/>
                <int:wire-tap pattern="*" order="-1" channel="logger"/>
            Obviously I prefer the "global one" approach ... so any suggestion is appreciated thus sparing me from writing a custom class and configuring it as a bean :-)

            Thanks and regards
            nuvola

            Comment

            Working...
            X