Giter Site home page Giter Site logo

mastermind1981 / spring-integration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from manojp1988/spring-integration

0.0 3.0 0.0 76 KB

Java dsl samples

Home Page: http://manojp1988.github.io/spring-integration

Ruby 0.41% Java 98.56% Groovy 1.04%

spring-integration's Introduction

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] (https://github.com/spring-projects/spring-integration-java-dsl/wiki/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?

spring-integration's People

Contributors

manojp1988 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.