יום ראשון, 10 במרץ 2013

10-03-2013 spring integration

GateWay

//Declare the gatway interface  

public interface ImyClient {
public Data processData (Data pData);
}

//Add gateway configuration :
<int:gateway id="myGateway"
default-request-channel="data-in-channel"
default-reply-channel="data-out-channel"
service-interface="com.mazalsadon.eilat.endpoints.gateway.ImyClient" />

//Test our code

public GatewayEndpointTest() {
ctx = new ClassPathXmlApplicationContext("endpoints-gateway-beans.xml");
// obtain our service interface
tradeGateway = ctx.getBean("myGateway",ImyClient .class);
}
public void publishTrade(Trade t) {
// call the method to publish the trade!
Trade it = tradeGateway.processTrade(t);
System.out.println("Trade Message published (Reply)."+it.getStatus());
}

public static void main(String[] args) {
GatewayEndpointTest test = new GatewayEndpointTest();
Trade t = new Trade();
test.publishTrade(t);
}
}

The spring activator


<int:service-activator
input-channel="data-in-channel"
output-channel="data-out-channel"
ref="dataProcessor"
method="receiveData" >
</int:service-activator>
<bean id="tradeProcessor"
class="com.mazalsadon.eilat.endpoints.gateway.TradeProcessor" />
The DataProcessor is a simple class that is invoked by the Activator endpoint when amessage arrives at the data-in-channel. It then processes the Trade and sends a reply
(via the return value):
public class TradeProcessor {
public Data receiveData(Data t) {
System.out.println("Received the Data via Gateway:"+t);
t.setStatus("PROCESSED");
return t;
}
}



 


אין תגובות:

הוסף רשומת תגובה