网站开发多少钱农民,谷歌seo教程,网站建设服务器介绍图片,高级网站建设费用本文是我们名为“ Spring Integration for EAI ”的学院课程的一部分。 在本课程中#xff0c;向您介绍了企业应用程序集成模式以及Spring Integration如何解决它们。 接下来#xff0c;您将深入研究Spring Integration的基础知识#xff0c;例如通道#xff0c;转换器和适… 本文是我们名为“ Spring Integration for EAI ”的学院课程的一部分。 在本课程中向您介绍了企业应用程序集成模式以及Spring Integration如何解决它们。 接下来您将深入研究Spring Integration的基础知识例如通道转换器和适配器。 在这里查看 目录 1.简介 2.系统概述 3.埃及剧院服务 4. Pantages剧院服务 5.用户界面 6.记录每个用户请求 7.丢弃无效的条目 8.选择要请求的剧院 9.请求埃及剧院 10.请求潘太及斯剧院 11.处理错误 11.1。 将消息存储到数据库 11.2。 向负责人发送电子邮件 12.关闭应用程序 13.看一看完整的流程 14.技术版本 1.简介 本教程将详细介绍一个应用程序的完整示例该应用程序使用Spring Integration提供的多个组件来为其用户提供服务。 该服务由一个系统提示用户选择不同的剧院组成。 选择后系统将向所选剧院的外部系统发出请求并返回其可用电影的列表。 每个电影院通过不同的API提供服务 我们将在解释每个外部系统的部分第三部分和第四部分中看到这一点。 2.系统概述 以下活动图显示了系统的高级视图。 图1 用户界面 在图的左侧我们开始了流程 请求用户条目。 系统显示的该进入请求以及对用户的系统响应都是与流集成的示例。 Web服务调用 根据用户的选择系统将从另一个外部系统检索影片列表。 埃及剧院通过HTTP公开其服务而潘塔基斯剧院则通过SOAP公开其服务。 错误处理 如果在流程中出现错误可能是由于意外异常或Web服务不可用系统会将信息发送到另外两个外部系统noSQL数据库 MongoDB 和电子邮件地址。 下一部分将更深入地介绍该系统的每个部分。 3.埃及剧院服务 埃及剧院系统通过HTTP公开他的服务。 在本节中我们将快速浏览该应用程序。 这是一个包含RESTful Web服务的Spring 4 MVC应用程序。 控制器将请求检索剧院中放映的所有可用电影 RestController
RequestMapping(value/films)
public class FilmController {FilmService filmService;Autowiredpublic FilmController(FilmService service) {this.filmService service;}RequestMapping(methodRequestMethod.GET)public Film[] getFilms() {return filmService.getFilms();}
} API很简单并且在此示例中服务将返回一些虚拟值因为本节的重点是仅提供有关调用外部系统的更多细节 Service(filmService)
public class FilmServiceImpl implements FilmService {Overridepublic Film[] getFilms() {Film film1 new Film(1, Bladerunner, 10am);Film film2 new Film(2, Gran Torino, 12pm);return new Film[]{film1, film2};}
} Spring配置基于注释 !-- Detects annotations like Component, Service, Controller, Repository, Configuration --
context:component-scan base-packagexpadro.spring.mvc.films.controller,xpadro.spring.mvc.films.service/!-- Detects MVC annotations like RequestMapping --
mvc:annotation-driven/ web.xml文件配置Web应用程序 !-- Root context configuration --
context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:xpadro/spring/mvc/config/root-context.xml/param-value
/context-param!-- Loads Spring root context, which will be the parent context --
listenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class
/listener!-- Spring servlet --
servletservlet-namespringServlet/servlet-nameservlet-classorg.springframework.web.servlet.DispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:xpadro/spring/mvc/config/app-context.xml/param-value/init-param
/servlet
servlet-mappingservlet-namespringServlet/servlet-nameurl-pattern/spring/*/url-pattern
/servlet-mapping 因此系统将处理发送到http://localhost:8080/rest-films/spring/films请求其中rest-films是应用程序的上下文路径。 4. Pantages剧院服务 Pantages Theatre服务通过SOAP公开其服务。 像埃及剧院一样它包含在Web应用程序中但在这种情况下它是通过Spring Web Services实现的 。 该终结filmRequest使用名称空间http://www.xpadro.spring.samples.com/films服务于filmRequest请求。 响应是从电影服务收到的结果中构建的 Endpoint
public class FilmEndpoint {Autowiredprivate FilmService filmService;PayloadRoot(localPartfilmRequest, namespacehttp://www.xpadro.spring.samples.com/films)public ResponsePayload FilmResponse getFilms() {return buildResponse();}private FilmResponse buildResponse() {FilmResponse response new FilmResponse();for (Film film : filmService.getFilms()) {response.getFilm().add(film);}return response;}
} 电影服务也是虚拟服务它将返回一些默认值 Service
public class FilmServiceImpl implements FilmService {Overridepublic ListFilm getFilms() {ListFilm films new ArrayList();Film film new Film();film.setId(new BigInteger((1)));film.setName(The Good, the Bad and the Uggly);film.setShowtime(6pm);films.add(film);film new Film();film.setId(new BigInteger((2)));film.setName(The Empire strikes back);film.setShowtime(8pm);films.add(film);return films;}
} Spring配置如下所示 !-- Detects Endpoint since it is a specialization of Component --
context:component-scan base-packagexpadro.spring.ws/!-- detects PayloadRoot --
ws:annotation-driven/ws:dynamic-wsdl idfilmDefinition portTypeNameFilms locationUrihttp://localhost:8080/ws-filmsws:xsd location/WEB-INF/schemas/xsd/film-service.xsd/
/ws:dynamic-wsdl 最后 web.xml文件 context-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:xpadro/spring/ws/config/root-config.xml/param-value
/context-paramlistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class
/listenerservletservlet-nameFilms Servlet/servlet-nameservlet-classorg.springframework.ws.transport.http.MessageDispatcherServlet/servlet-classinit-paramparam-namecontextConfigLocation/param-nameparam-valueclasspath:xpadro/spring/ws/config/servlet-config.xml/param-value/init-paramload-on-startup1/load-on-startup
/servletservlet-mappingservlet-nameFilms Servlet/servlet-nameurl-pattern/films/*/url-pattern
/servlet-mapping 根据此配置Pantages Theatre应用程序将处理发送到http://localhost:8080/ws-films/films请求其中ws-films是应用程序的上下文路径。 5.用户界面 一旦我们了解了将与Spring Integration应用程序进行通信的外部系统是什么让我们继续看一下如何构建此应用程序。 独立应用程序从引导Spring上下文的主要方法开始该方法包含我们所有的集成组件。 接下来它提示用户输入他的选择 public class TheaterApp {private static Logger logger LoggerFactory.getLogger(mainLogger);static AbstractApplicationContext context;public static void main(String[] args) {context new ClassPathXmlApplicationContext(classpath:xpadro/spring/integration/config/int-config.xml);context.registerShutdownHook();logger.info(\\nSelect your option (1-Egyptian Theater / 2-Pantages Theater / 0-quit):\\n);}public static void shutdown() {logger.info(Shutting down...);context.close();}
} 该应用程序还实现了一种关闭方法该方法将由用户调用。 我们将在后面的部分中更详细地介绍这一点。 好的现在用户选择将如何进入消息传递系统 这是与流集成起作用的地方。 消息传递系统的系统条目是使用入站通道适配器实现的该适配器将从stdin System.in 中读取。 !-- System entry --
int-stream:stdin-channel-adapter idconsoleIn channelsystemEntryint:poller fixed-delay1000 max-messages-per-poll1 /
/int-stream:stdin-channel-adapter 通过使用轮询器入站通道适配器将尝试每秒从System.read中读取并将结果放入systemEntry通道。 现在我们收到了一条带有用户条目作为其有效负载的Spring Integration消息。 我们可以使用端点来转换数据并将其发送到所需的系统。 示例控制台将提示用户在不同的剧院之间进行选择 2014-04-11 13:04:32,959|AbstractEndpoint|started org.springframework.integration.config.ConsumerEndpointFactoryBean#7Select your option (1-Egyptian Theater / 2-Pantages Theater / 0-quit):6.记录每个用户请求 系统要做的第一件事是记录用户选择。 这是通过使用丝锥完成的 。 此窃听是拦截器的实现该拦截器将拦截通过通道在我们的情况下为systemEntry通道传播的消息。 它不会改变流量 该消息将继续到达其目的地但有线分流器还将其发送到另一个通道通常用于监视。 在我们的应用程序中该消息还将发送到日志记录通道适配器。 int:channel idsystemEntryint:interceptorsint:wire-tap channelrequestLoggingChannel//int:interceptors
/int:channelint:logging-channel-adapter idrequestLoggingChannel expressionUser selection: .concat(payload) levelINFO/ 日志记录通道适配器由LoggingChannelAdapterParser实现。 它基本上创建了一个LoggingHandler 它将使用Apache Commons Logging库记录消息的有效负载。 如果要记录完整消息而不是仅记录其有效负载则可以将log-full-message属性添加到log-full-message记录通道适配器。 示例日志显示用户所做的选择 Select your option (1-Egyptian Theater / 2-Pantages Theater / 0-quit):1
2014-04-11 13:06:07,110|LoggingHandler|User selection: 17.丢弃无效的条目 看一眼用户提示我们看到系统接受三个有效条目 logger.info(\\nSelect your option (1-Egyptian Theater / 2-Pantages Theater / 0-quit):\\n) 无效条目的处理非常简单 系统将过滤无效条目以防止它们在流程中向前移动。 这些丢弃的消息然后将被发送到discards通道。 订阅invalidEntries丢弃通道还有另一个流通道适配器在这种情况下是出站适配器 int:filter input-channelsystemEntry output-channelvalidEntriesChannel refentryFilter discard-channelinvalidEntries/!-- Invalid entries (show on console) --
int:chain input-channelinvalidEntriesint:transformer refdiscardsTransformer/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue /
/int:chain 该适配器的功能是写入stdout System.out 因此用户将收到用户在控制台上输入了无效请求的信息。 要记住的一件事是我们没有创建invalidEntries通道。 适配器将通过匿名临时直接通道连接到过滤器。 示例控制台显示用户输入了无效的选择。 Select your option (1-Egyptian Theater / 2-Pantages Theater / 0-quit):8
2014-04-11 13:07:41,808|LoggingHandler|User selection: 8
Invalid entry: 88.选择要请求的剧院 成功通过上一个过滤器的有效条目将被发送到路由器 !-- Valid entries (continue processing) --
int:channel idvalidEntriesChannel /
int:router input-channelvalidEntriesChannel refcinemaRedirector/ 该路由器负责确定用户需要哪个外部系统的信息。 它还将检测用户何时要关闭该应用程序 Component(cinemaRedirector)
public class CinemaRedirector {private static final String CINEMA_EGYPTIAN_CHANNEL egyptianRequestChannel;private static final String CINEMA_PANTAGES_CHANNEL pantagesRequestChannel;private static final String QUIT_REQUEST_CHANNEL quitRequestChannel;Routerpublic String redirectMessage(MessageString msg) {String payload msg.getPayload();if (1.equals(payload)) {return CINEMA_EGYPTIAN_CHANNEL;}else if (2.equals(payload)) {return CINEMA_PANTAGES_CHANNEL;}return QUIT_REQUEST_CHANNEL;}
} 因此这里的流程分为三个不同的通道每个剧院的请求和完成流程的请求。 9.请求埃及剧院 为了与埃及剧院系统进行通信我们需要发送一个HTTP请求。 我们通过使用HTTP出站网关来完成此任务。 int-http:outbound-gateway urlhttp://localhost:8080/rest-films/spring/films expected-response-typejava.lang.String http-methodGET charsetUTF-8/ 该网关配置了几个属性 expected-response-type Web服务返回的返回类型将是一个字符串其中包含带有电影列表的JSON。 http-method 我们正在发出GET请求。 charset 用于将有效载荷转换为字节的字符集。 收到响应后我们将使用转换器将返回的JSON转换为Java对象。 在我们的例子中我们将响应转换为Film数组 int:json-to-object-transformer typexpadro.spring.integration.model.Film[]/ 接下来服务激活器将遍历数组并构建更适合用户的String。 int:service-activator refrestResponseHandler/ 实现如下所示 Component(restResponseHandler)
public class RestResponseHandler {private static final String NEW_LINE \\n;ServiceActivatorpublic String handle(MessageFilm[] msg) {Film[] films msg.getPayload();StringBuilder response new StringBuilder(NEW_LINE);if (films.length 0) {response.append(Returned films: NEW_LINE);}else {response.append(No films returned NEW_LINE);}for (Film f:films) {response.append(f.getName()).append(NEW_LINE);}return response.toString();}
} 最后我们将通过在控制台上打印响应显示给用户。 我们正在使用与用于向用户显示其无效条目的通道适配器相同的通道适配器。 适配器将写入System.out int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue / 下一个代码段显示了完整的请求。 由于我不想为这些端点之间的每次交互创建消息通道因此我使用了消息处理程序链。 当我们在序列中有多个端点时这种类型的端点简化了所需的XML配置。 通过使用消息处理程序链其所有端点都通过匿名直接通道连接。 !-- Egyptian Theater request --
int:chain input-channelegyptianRequestChannelint-http:outbound-gateway urlhttp://localhost:8080/rest-films/spring/films expected-response-typejava.lang.String http-methodGET charsetUTF-8/int:json-to-object-transformer typexpadro.spring.integration.model.Film[]/int:service-activator refrestResponseHandler/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue /
/int:chain 示例向用户显示了埃及剧院的电影列表。 1
2014-04-11 14:26:20,981|LoggingHandler|User selection: 1Returned films:
Bladerunner
Gran Torino10.请求潘太及斯剧院 我们将需要一个Web服务网关来与Pantages Theatre系统进行交互但是首先我们必须构建一个filmRequest类型的请求对象以便由埃及Web服务端点进行服务。 我们正在使用转换器将消息更改为电影Web服务请求 int:transformer refsoapRequestTransformer/ 实现 Component(soapRequestTransformer)
public class SoapRequestTransformer {Transformerpublic Message? createRequestMessage(MessageString msg) {return MessageBuilder.withPayload(new FilmRequest()).copyHeadersIfAbsent(msg.getHeaders()).build();}
} 我们获得了请求对象因此我们现在可以使用Web服务网关来调用Web服务 int-ws:outbound-gateway urihttp://localhost:8080/ws-films/films marshallermarshaller unmarshallermarshaller/ 如上一教程中所述将需要编组器来转换请求和响应。 对于此任务我们将使用oxm名称空间 oxm:jaxb2-marshaller idmarshaller contextPathxpadro.spring.integration.ws.types / 当我们收到Web服务响应时它将采用FilmResponse的形式。 序列中的下一个端点将调整响应并返回一个String以便在下一阶段向用户显示 int:service-activator refsoapResponseHandler/ 实现 Component(soapResponseHandler)
public class SoapResponseHandler {private static final String NEW_LINE \\n;ServiceActivatorpublic String handle(MessageFilmResponse msg) {FilmResponse response msg.getPayload();StringBuilder resp new StringBuilder(NEW_LINE);if (response.getFilm().size() 0) {resp.append(Returned films: NEW_LINE);}else {resp.append(No films returned NEW_LINE);}for (Film f : response.getFilm()) {resp.append(f.getName()).append(NEW_LINE);}return resp.toString();}
} 与埃及请求一样该请求也以另一个流出站通道适配器结束 int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue / 由于我们还有另一个端点序列因此我们使用消息处理程序链来最大程度地减少所需的配置量 !-- Pantages Theater request --
int:chain input-channelpantagesRequestChannelint:transformer refsoapRequestTransformer/int-ws:outbound-gateway urihttp://localhost:8080/ws-films/films marshallermarshaller unmarshallermarshaller/int:service-activator refsoapResponseHandler/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue /
/int:chain 示例向用户显示了Pantages Theatre电影列表。 2
2014-04-11 14:27:54,796|LoggingHandler|User selection: 2Returned films:
The Good, the Bad and the Uggly
The Empire strikes back11.处理错误 如果出现任何问题我们需要以某种方式进行注册。 发生这种情况时应用程序将执行以下两项操作 将消息存储到数据库。 发送电子邮件到指定地址。 Spring Integration消息通道名为errorChannel将接收消息处理程序抛出的MessagingException类型的错误。 这个特殊频道是一个发布-订阅频道这意味着它可以有多个订阅者。 我们的应用程序订阅了两个端点以便执行先前指定的两个操作。 将消息存储到数据库 以下服务激活器已预订到错误通道因此它将收到MessagingException int:service-activator refmongodbRequestHandler/ 这个激活器将要做的是解决将请求发送到哪个剧院然后它将构建一个FailedMessage对象其中包含我们要记录的信息 Component(mongodbRequestHandler)
public class MongodbRequestHandler {private Logger logger LoggerFactory.getLogger(this.getClass());Autowiredprivate TheaterResolver theaterResolver;public FailedMessage handle(MessagingException exc) {logger.error(Request failed. Storing to the database);String theater theaterResolver.resolve(exc);FailedMessage failedMsg new FailedMessage(new Date(), exc.getMessage(), theater);return failedMsg;}
} 失败的消息结构包含基本信息 public class FailedMessage implements Serializable {private static final long serialVersionUID 4411815706008283621L;private final Date requestDate;private final String messsage;private final String theater;public FailedMessage(Date requestDate, String message, String theater) {this.requestDate requestDate;this.messsage message;this.theater theater;}public Date getRequestDate() {return new Date(requestDate.getTime());}public String getMessage() {return this.messsage;}public String getTheater() {return this.theater;}
} 构建消息后我们将使用mongodb出站通道适配器将其存储到数据库中 int-mongodb:outbound-channel-adapter idmongodbAdapter collection-namefailedRequests mongodb-factorymongoDbFactory / 这部分流程的完整代码如下所示 import resourcemongodb-config.xml/int:chain input-channelerrorChannelint:service-activator refmongodbRequestHandler/int-mongodb:outbound-channel-adapter idmongodbAdapter collection-namefailedRequests mongodb-factorymongoDbFactory /
/int:chain mongodb-config.xml文件包含特定于MongoDB配置的信息 bean idmongoDbFactory classorg.springframework.data.mongodb.core.SimpleMongoDbFactoryconstructor-argbean classcom.mongodb.Mongo//constructor-argconstructor-arg valuejcgdb/
/beanbean idmongoDbMessageStore classorg.springframework.integration.mongodb.store.ConfigurableMongoDbMessageStoreconstructor-arg refmongoDbFactory/
/bean 示例以下屏幕快照显示了两个失败请求后的集合每个剧院类型一个 图2 向负责人发送电子邮件 订阅错误通道的另一个端点是邮件请求处理程序。 int:service-activator refmailRequestHandler/ 此处理程序负责创建MailMessage以便将其发送到邮件网关 Component(mailRequestHandler)
public class MailRequestHandler {private Logger logger LoggerFactory.getLogger(this.getClass());Autowiredprivate TheaterResolver theaterResolver;ServiceActivatorpublic MailMessage handle(MessagingException exc) {logger.error(Request failed. Sending mail);MailMessage mailMsg new SimpleMailMessage();mailMsg.setFrom(Theater.System);mailMsg.setTo(my.mailgmail.com);mailMsg.setSubject(theater request failed);String theater theaterResolver.resolve(exc);StringBuilder textMessage new StringBuilder(Invocation to ).append(theater).append( failed\\n\\n).append(Error message was: ).append(exc.getMessage());mailMsg.setText(textMessage.toString());return mailMsg;}
} 剧院解析器检查用户选择并返回所请求剧院的名称。 完整的配置如下 int:chain input-channelerrorChannelint:service-activator refmailRequestHandler/int-mail:outbound-channel-adapter mail-sendermailSender /
/int:chainimport resourcemail-config.xml/ mail-config.xml包含Spring邮件发件人的配置 bean idmailSender classorg.springframework.mail.javamail.JavaMailSenderImplproperty namehost valuesmtp.gmail.com /property nameport value465 /property nameusername valuemy.mailgmail.com /property namepassword valuemyPassword /property namejavaMailPropertiespropsprop keymail.smtp.starttls.enabletrue/propprop keymail.smtp.authtrue/propprop keymail.smtp.socketFactory.classjavax.net.ssl.SSLSocketFactory/prop/props/property
/bean 示例邮件发送到gmail帐户 图3 12.关闭应用程序 出现提示时用户可以通过输入零来决定完成应用程序的执行。 当他决定这样做时路由器会将消息重定向到quitRequestChannel通道请参阅第8节。 订阅此频道我们已经配置了消息处理程序链 !-- Quit message (shutdown application) --
int:chain input-channelquitRequestChannelint:service-activator refshutdownActivator/int-event:outbound-channel-adapter/
/int:chain 服务激活器将创建一个ShutdownEvent并将其返回以便由消息处理程序链的下一个端点进行处理 Component(shutdownActivator)
public class ShutdownActivator {ServiceActivatorpublic ShutdownEvent createEvent(MessageString msg) {return new ShutdownEvent(this);}
} ShutdownEvent是ApplicationEvent的实例。 public class ShutdownEvent extends ApplicationEvent {private static final long serialVersionUID -198696884593684436L;public ShutdownEvent(Object source) {super(source);}public ShutdownEvent(Object source, String message) {super(source);}public String toString() {return Shutdown event;}
} 事件出站通道适配器将发布为ApplicationEvent 将发送到订阅该通道的任何消息。 这样它们将由在应用程序上下文中注册的任何ApplicationListener实例处理。 但是如果消息的有效负载是ApplicationEvent的实例则它将按原样传递。 如前面的代码所示我们的ShutdownEvent是ApplicationEvent一个实例。 侦听此类事件我们已经注册了一个侦听器 Component(shutdownListener)
public class ShutdownListener implements ApplicationListenerShutdownEvent {Overridepublic void onApplicationEvent(ShutdownEvent event) {TheaterApp.shutdown();}
} 侦听器用于关闭应用程序。 如果您记得第五节中的关闭方法 Theater应用程序将关闭应用程序上下文。 13.看一看完整的流程 为了简化起见我将所有集成元素都放在同一个文件中但是我们可以考虑将其拆分为较小的文件 beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:inthttp://www.springframework.org/schema/integrationxmlns:int-jmshttp://www.springframework.org/schema/integration/jmsxmlns:int-streamhttp://www.springframework.org/schema/integration/streamxmlns:int-eventhttp://www.springframework.org/schema/integration/eventxmlns:int-httphttp://www.springframework.org/schema/integration/httpxmlns:int-wshttp://www.springframework.org/schema/integration/wsxmlns:int-mongodbhttp://www.springframework.org/schema/integration/mongodbxmlns:int-mailhttp://www.springframework.org/schema/integration/mailxmlns:oxmhttp://www.springframework.org/schema/oxmxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-3.0.xsdhttp://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-3.0.xsdhttp://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-3.0.xsdhttp://www.springframework.org/schema/integration/event http://www.springframework.org/schema/integration/event/spring-integration-event-3.0.xsdhttp://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-3.0.xsdhttp://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws-3.0.xsdhttp://www.springframework.org/schema/integration/mongodb http://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb-3.0.xsdhttp://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail-3.0.xsdhttp://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsdcontext:component-scan base-packagexpadro.spring.integration/!-- System entry --int-stream:stdin-channel-adapter idconsoleIn channelsystemEntryint:poller fixed-delay1000 max-messages-per-poll1 //int-stream:stdin-channel-adapterint:channel idsystemEntryint:interceptorsint:wire-tap channelrequestLoggingChannel//int:interceptors/int:channelint:logging-channel-adapter idrequestLoggingChannel expressionUser selection: .concat(payload) levelINFO/int:filter input-channelsystemEntry output-channelvalidEntriesChannel refentryFilter discard-channelinvalidEntries/!-- Invalid entries (show on console) --int:chain input-channelinvalidEntriesint:transformer refdiscardsTransformer/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue //int:chain!-- Valid entries (continue processing) --int:channel idvalidEntriesChannel /int:router input-channelvalidEntriesChannel refcinemaRedirector/!-- Quit message (shutdown application) --int:chain input-channelquitRequestChannelint:service-activator refshutdownActivator/int-event:outbound-channel-adapter//int:chain!-- Continue processing (get data) --!-- Pantages Theater request --int:chain input-channelpantagesRequestChannelint:transformer refsoapRequestTransformer/int-ws:outbound-gateway urihttp://localhost:8080/ws-films/films marshallermarshaller unmarshallermarshaller/int:service-activator refsoapResponseHandler/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue //int:chainoxm:jaxb2-marshaller idmarshaller contextPathxpadro.spring.integration.ws.types /!-- Egyptian Theater request --int:chain input-channelegyptianRequestChannelint-http:outbound-gateway urlhttp://localhost:8080/rest-films/spring/films expected-response-typejava.lang.String http-methodGET charsetUTF-8/int:json-to-object-transformer typexpadro.spring.integration.model.Film[]/int:service-activator refrestResponseHandler/int-stream:stdout-channel-adapter idconsoleOut append-newlinetrue //int:chain!-- Error handling --import resourcemongodb-config.xml/int:chain input-channelerrorChannelint:service-activator refmongodbRequestHandler/int-mongodb:outbound-channel-adapter idmongodbAdapter collection-namefailedRequests mongodb-factorymongoDbFactory //int:chainint:chain input-channelerrorChannelint:service-activator refmailRequestHandler/int-mail:outbound-channel-adapter mail-sendermailSender //int:chainimport resourcemail-config.xml//beans14.技术版本 对于此应用程序我使用了Spring框架的3.2.8发行版和Spring Integration的最新3.0.2发行版。 完整的依赖项列表如下所示 propertiesspring-version3.2.8.RELEASE/spring-versionspring-integration-version3.0.2.RELEASE/spring-integration-versionslf4j-version1.7.5/slf4j-versionjackson-version2.3.0/jackson-versionjavax-mail-version1.4.1/javax-mail-version
/propertiesdependencies!-- Spring Framework - Core --dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring-version}/version/dependency!-- Spring Framework - Integration --dependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-core/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-jms/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-stream/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-event/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-http/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-ws/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-mongodb/artifactIdversion${spring-integration-version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-mail/artifactIdversion${spring-integration-version}/version/dependency!-- javax.mail --dependencygroupIdjavax.mail/groupIdartifactIdmail/artifactIdversion${javax-mail-version}/version/dependency!-- Jackson --dependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-core/artifactIdversion${jackson-version}/version/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion${jackson-version}/version/dependency!-- Logging --dependencygroupIdorg.slf4j/groupIdartifactIdslf4j-api/artifactIdversion${slf4j-version}/version/dependencydependencygroupIdorg.slf4j/groupIdartifactIdslf4j-log4j12/artifactIdversion${slf4j-version}/version/dependency
/dependencies翻译自: https://www.javacodegeeks.com/2015/09/spring-integration-full-example.html