0

I've an XML config for mail service in spring, that I'd like to transform to JAVA config.

XML Looks like this

<int:chain id="chain"
           input-channel="outMailError"
    output-channel="outMailEntry">
    <int:poller max-messages-per-poll="1" fixed-rate="20000" />
    <int:transformer ref="mailSendErrorTransformer" />
</int:chain>

<int:channel id="outMailError">
    <int:queue capacity="500" />
</int:channel>

<int:channel id="outboundMailEntry" />

I was able to convert the channels to

@Bean
public DirectChannel outboundMailEntry() {
    return new DirectChannel();
}

@Bean
public QueueChannel outboundMailErrorChannel() {
    return new QueueChannel(500);
}

But I don't know how to the same for int:chain. I was able to debug and find out what type of bean does spring instantiate for "chain" part of xml - it is PollingConsumer that takes 2 params PollableChannel inputChannel, MessageHandler handler.

The first one is not a problem since I already have that, it is the

@Qualifier("outMailError")
QueueChannel channel

But I do not know about the second one... Spring itself initializes some MessageHandlerChain but I was unable to to set the outMailEntry to it and also dont know about the poller and transformer.. any ídeas?

1 Answer 1

2

There is no chain equivalent in Java Config. It was designed especially for XML to let to minimize XML coding.

On the other hand it doesn't look like you need that <chain> at all: you have only one <int:transformer> over there.

In Java Config you would use a @Trasnoformer annotation on your mailSendErrorTransformer method with appropriate inputChannel and outputChannel attributes. The <int:poller> equivalent is also present over there as a poller attribute with resective @Poller configuration.

See more info in the docs starting from here: https://docs.spring.io/spring-integration/docs/current/reference/html/overview.html#configuration-enable-integration

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, one more thing if you could help me... what about config such as this? <int:header-enricher input-channel="outboundMail" output-channel="outboundMailEntry"> <int:error-channel ref="outboundMailErrorChannel" /> </int:header-enricher> I think I should convert it to import org.springframework.integration.endpoint.EventDrivenConsumer?
See @ServiceActivator on @Bean method and DefaultHeaderEnricher. Of course it even would be better to go Java DSL... everything is in that doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.