0
votes

am new to Spring Integration

my objective is passing message to one channel to another (chain process)

Channel1 ---> chennal2 --> chennal3 ---> chennal4. (Msg1)       (Msg2)                (Msg3)                    (Msg4)

     \                         \                       /                          /

       \                        \                   /                          /          

                            errorChennal (Msg5)

1.       Msg1(EmployeeObject), Msg2 (DetailsObjet), Msg3(VerificationObject), Msg4(FinalObject), Msg5(ErrorObject)

    Each channel payloads will have different Class Objects.
  1.    All the channel need to be communicated to "errorChennal" in case of Exception, validation error, etc.

Tried: 1. when I tried with @transformer am not able to communicate to "erroeChannel".

  1. when I tried with @Router(header-value-router) Message transform not happing. Msg1 object is to all object

Question:   How do i route one channel to specific channel with message transformer?

FOUND ANSWER

Configuration:

<int:channel id="channel1"/>
<int:channel id="channel2"/>
<int:channel id="channel3"/>
<int:channel id="channel4"/>

<int:service-activator input-channel="channel1" ref="firstChannel" method="doProcess1" />
<int:service-activator input-channel="channel2" ref="secondChannel" method="doProcess2" />
<int:service-activator input-channel="channel3" ref="thirdChannel" method="doProcess3" />
<int:service-activator input-channel="channel4" ref="forthChannel" method="doProcess4" />
<int:service-activator input-channel="errorChannel" ref="errorHandlerChannel" method="doErrorProcess" />

Java Code: 

public FirstChannel {

    private Map<String, MessageChannel> msgChannels;
    boolean isError = false;
    @Autowired
    public ScheduleParser(Map<String, MessageChannel> msgChannels) {
        super();
        this.msgChannels = msgChannels;
    }

    public void doprocess1(Message<?> message){
    File file = (File) message.getPayload();
    //business code 

    if(!isError)
        //transforming the messae
        msgChannels.get("channel2").send(new GenericMessage(EmployeeVO , headersMap));
    else 
        msgChannels.get("errorChannel").send(new GenericMessage(ObjectVO , headersMap));
}

}

Same way Other channels Code will be

1

1 Answers

0
votes

Channels aren't connected to each other they are connected to endpoints.

Transformers don't route, routers route.

You need something like

channel1->payload-type-router

type1Channel->...
type2Channel->...
...

possibly with a different transformer for each payload type downstream.

It's generally better to show the configuration you have tried rather than some abstraction like you have shown.

The error flow configuration depends on what starts your flow (gateway, poller, etc) - i.e. what is upstream of channel1.

EDIT

Your configuration is completely wrong. For example, you currently have two subscribers on channel1 - a header value router and service activator.

Messages arriving on channel1 will alternately go to one or the other - messages going to the service activator will never go to the router.

Without knowing the complete picture, I am guessing you need something like...

channel1->serviceActivator1->channel1toRouter->router(channel2 or failed)
channel2->serviceActivator2->channel2toRouter->router(channel2 or failed)
...