Spring-Integration:初探

2020.07.20 02:07:43
11
阅读约 1 分钟
Scroll down

基本概念 #

参考:https://www.jianshu.com/p/bf1643539f99

demo下载 #

来源:https://github.com/spring-projects/spring-integration-samples

例子解析 #

2.spring integration对于企业集成模式的支持

2.1Message:一个信息的单元,通常有消息头(header)和消息内容(payload)组成

2.2Message channel:消息处理节点之间的连接,负责将Message从生产者传输到消费者。

根据消费者的多少,可分为point to point和publish-subscribe两种

httpClient–>server #

消息发送网关接口 #

public interface RequestGateway {

	String echo(String request);

}

客户端xml配置 #

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:int="http://www.springframework.org/schema/integration"
	xmlns:int-http="http://www.springframework.org/schema/integration/http"
	xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd
		http://www.springframework.org/schema/integration/http https://www.springframework.org/schema/integration/http/spring-integration-http.xsd">

	<int:gateway id="requestGateway" 
	             service-interface="org.springframework.integration.samples.http.RequestGateway"
	             default-request-channel="requestChannel"/>
	
	<int:channel id="requestChannel"/>

	<int-http:outbound-gateway request-channel="requestChannel" 
					           url="http://localhost:8089/http/receiveGateway"
					           http-method="POST"
					           expected-response-type="java.lang.String"/>

</beans>

发起http请求 #

public class HttpClientDemo {

	private static Log logger = LogFactory.getLog(HttpClientDemo.class);

	public static void main(String[] args) {
		ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
				"/META-INF/spring/integration/http-outbound-config.xml");
		RequestGateway requestGateway = context.getBean("requestGateway", RequestGateway.class);
		String reply = requestGateway.echo("Hello");
		logger.info("\n\n++++++++++++ Replied with: " + reply + " ++++++++++++\n");
		context.close();
	}

}

客户端只要写简单的controller接收请求即可。

win10启用telnet #

img

TCP-HTTP-TCP关系 #

img

阅读:11 . 字数:185 发布于 2 个月前
Copyright 2018-2020 Siques