WendyG
WendyG

Reputation: 587

spring Integration configuration logging channel adaptor

Currently using spring integration 4.2.8.

I have managed quite a lot of my previous question about this but I have 1 piece of xml configuration I can't work out how to replace in the new configuration class: it is the logging-channel-adapter there doesn't seem to be a matching class.

The only class I can find is the LoggingChannelAdapterParser but that is just designed to read the xml and output something ( AbstractBeanDefinition)

How do I specify a logging output in the recipientListRouter?

  <int:logging-channel-adapter id="dlq-logger" level="ERROR" expression="'Unknown action type ['
    .concat(headers.actionType)
    .concat('] for message with payload ')
    .concat(payload)"/>

<int:recipient-list-router input-channel="jms-inbound" id="action-type-router">
        <int:recipient channel="inbound1" selector-expression="headers.actionType == 'CREATE'"/>
        <int:recipient channel="inbound2" selector-expression="headers.actionType == 'UPDATE'"/>
        <int:recipient channel="dlq-logger" selector-expression="headers.actionType != 'UPDATE' and headers.actionType != 'CREATE' "/>
    </int:recipient-list-router>

Here is the recipinetListRouter constructor

@ServiceActivator(inputChannel = "routingChannel")
  @Bean
  RecipientListRouter actionTypeRouter(){

    RecipientListRouter router = new RecipientListRouter();
    router.setChannels()
    router.addRecipient("Inbound1", "headers.actionType == 'CREATE'")
    router.addRecipient("Inbound2", "headers.actionType == 'UPDATE'")
    router.addRecipient("dlqLogger", "headers.actionType != 'UPDATE' and headers.actionType != 'CREATE' ")
  }

Edit - from gary's answer If as does seem sensible this is the most likely answer which way do I wire it, can a logging handler be a recipient? if so do i still need the ServiceActivator annotation? Or is it a 2 way relationship?

@Bean
@ServiceActivator(inputChannel = "logChannel")
public LoggingHandler logging() {
    LoggingHandler adapter = new LoggingHandler(LoggingHandler.Level.DEBUG);
    adapter.setLoggerName("TEST_LOGGER");
    adapter.setLogExpressionString("headers.id + ': ' + payload");
    return adapter;
}

Upvotes: 1

Views: 2279

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

It's called LoggingHandler - see the documentation.

@Bean
@ServiceActivator(inputChannel = "logChannel")
public LoggingHandler logging() {
    LoggingHandler adapter = new LoggingHandler(LoggingHandler.Level.DEBUG);
    adapter.setLoggerName("TEST_LOGGER");
    adapter.setLogExpressionString("headers.id + ': ' + payload");
    return adapter;
}

EDIT from Artem Bilan

Also pay attention to the docs of the <int:logging-channel-adapter>:

<xsd:element name="logging-channel-adapter">
    <xsd:annotation>
        <xsd:documentation>
            Defines a Message Producing Endpoint for the
            'org.springframework.integration.handler.LoggingHandler'.
        </xsd:documentation>
    </xsd:annotation>

And then go to this Docs for more understanding the model: https://docs.spring.io/spring-integration/reference/html/overview.html#_finding_class_names_for_java_and_dsl_configuration

Comment From Gary:

Consuming endpoints consist of 2 beans; a consumer (with the input channel) and message handler; the XML generates both; with Java Configuration, the @Bean creates the handler and the @ServiceActivator defines the consumer. So in your case, it would be @ServiceActivator(inputChannel="dlqLogger"). The router has the selector expressions. –

Upvotes: 2

Related Questions