Welcome to my Github Spring-integration-java-dsl repository!

This repository contains samples, questions&answers posted to spring-integration authors. Thanks to @garyrussell and @artembilan for their support.

Why dsl than xml?

Java dsl is better in a way that we don't need to write complex xml integration tags, more writing to define each components. Java dsl is more reable, more resuable.

Reference: Spring-Integration-Java-DSL-Reference.

Sample Flow:

A sample outbound gateway can have transformer which transform the canonical object to request object, header enricher which enriches header values, and call the outbound gateway and then transform the response object to canonical response object. This can be code in below dsl way.

Java configuration

  @Configuration
  @EnableIntegration // Enables integration infrastructure like channels.
  @IntegrationComponentScan // Like component scan, this will scan integration components like @MessaginGateway etc.
  @EnableMessageHistory // This enables adding message flow history in the header.
  public  class ContextConfiguration {
  }

Gateway:

  @MessagingGateway
  public interface HelloGateway {
    @Gateway(requestChannel = "helloRequestChannel")
    String sayHello(String payload);
  }

Channel definition:

 @Bean
 public MessageChannel helloRequestChannel(){
   return MessageChannels.direct().get();
 }

Integration flow:

  @Bean
  public IntegrationFlow sayHelloFlow(){
   return IntegrationFlow.from("helloRequestChannel")
                         .transform(requestTransformer)
                         .enrichHeaders(headerEnricher)
                         .handle(httpOutboundGateway)
                         .transform(responseTransformer)
                         .get();
   }

How to invoke the gateway

  1. Invoke through simple java invocation.
  2. Put message into the channel.
  sayHello("dsl"); // Java method invocation.
<!-- below enricher puts payload into the channel we defined above and sets into property as usual. -->
  <int:enricher input-channel="HELLO_ENRCH_CHNL"
        request-channel="helloRequestChannel">
        <int:property name="name" expression="payload.name" />
    </int:enricher>

Working example represents above can be found here.

If you see above, you can find the difference how dsl improves readability. Instead of we defining channels, spring generates channels for us. And you can see them if you enable logging.

Debugging.

All channels are created based on the flow name we define. If you see from above example, spring generates sayHelloFlow.channel#0, sayHelloFlow.channel#1 etc.

Examples:

  1. Flow reuse. This is something we wanted to achieve using dsl. With xml, we had to same kind of flow redundantly in many places.
  2. Advice for gateways. We can ran aop on the gateways. This is not specific to dsl though.
  3. Global channel interceptors/.
  4. Re-route error channel to caller..
  5. Splitter-Aggregator
  6. Expression based router.
  7. Recipient list router.
  8. Header value router.

More will come...

Questions:

  1. How to put back errorchannel message into reply channel?
  2. How to carry over header info to errorChannel?
  3. How to use AOP on spring integration gateways?
  4. How to import spring Java dsl config into XML configuration?
  5. What is the difference between grouping config via @import and @ContextConfiguration.?
  6. How to create custom component and add it to flow in spring java dsl?
  7. Do i need to do declare a channel info in dsl always?
  8. How to do split-aggregate in java dsl by invoking another flow?
  9. How to do channel interceptor based on pattern using JAVA DSL in Spring Integration?