77import org .springframework .context .annotation .Configuration ;
88import org .springframework .integration .annotation .Filter ;
99import org .springframework .integration .annotation .IntegrationComponentScan ;
10+ import org .springframework .integration .annotation .ServiceActivator ;
1011import org .springframework .integration .annotation .Transformer ;
1112import org .springframework .integration .channel .DirectChannel ;
1213import org .springframework .integration .config .EnableIntegration ;
1314import org .springframework .integration .core .MessageSelector ;
1415import org .springframework .integration .filter .MessageFilter ;
1516import org .springframework .integration .json .JsonToObjectTransformer ;
1617import org .springframework .integration .json .ObjectToJsonTransformer ;
18+ import org .springframework .integration .router .PayloadTypeRouter ;
1719import org .springframework .integration .support .json .Jackson2JsonObjectMapper ;
1820import org .springframework .integration .transformer .HeaderEnricher ;
1921import org .springframework .integration .transformer .support .HeaderValueMessageProcessor ;
2224import org .springframework .messaging .MessageChannel ;
2325
2426import com .fasterxml .jackson .databind .ObjectMapper ;
27+ import com .springboot .model .Address ;
2528import com .springboot .model .Student ;
2629
2730@ Configuration
@@ -33,12 +36,13 @@ public class IntegrationConfig {
3336 public MessageChannel recieverChannel () {
3437 return new DirectChannel ();
3538 }
36- 37- // @Bean
38- // public MessageChannel replyChannel() {
39- // return new DirectChannel();
40- // }
4139
40+ // @Bean
41+ // public MessageChannel replyChannel() {
42+ // return new DirectChannel();
43+ // }
44+ 45+ //Filter Example
4246 @ Filter (inputChannel = "router.channel" )
4347 @ Bean
4448 public MessageFilter filter () {
@@ -52,7 +56,8 @@ public boolean accept(Message<?> message) {
5256 filter .setOutputChannelName ("student.channel" );
5357 return filter ;
5458 }
55- 59+ 60+ //Transformer Example
5661 @ Bean
5762 @ Transformer (inputChannel = "integration.student.gateway.channel" , outputChannel = "integration.student.toConvertObject.channel" )
5863 public HeaderEnricher enrichHeader () {
@@ -80,4 +85,15 @@ public Jackson2JsonObjectMapper getMapper() {
8085 JsonToObjectTransformer jsonToObjectTransformer () {
8186 return new JsonToObjectTransformer (Student .class );
8287 }
88+ 89+ // PayloadTypeRouter Example
90+ @ ServiceActivator (inputChannel = "router.channel" )
91+ @ Bean
92+ public PayloadTypeRouter payloadRouter () {
93+ PayloadTypeRouter router = new PayloadTypeRouter ();
94+ router .setChannelMapping (Student .class .getName (), "student.enrich.header.channel" );
95+ router .setChannelMapping (Address .class .getName (), "address.enrich.header.channel" );
96+ return router ;
97+ }
98+ 8399}
0 commit comments