Browse Source

增加日志框架,增加连接配置

menglu 3 years ago
parent
commit
c3542385f0

+ 11 - 2
ibms-data-sdk/pom.xml

@@ -1,5 +1,4 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>com.persagy</groupId>
 	<artifactId>ibms-data-sdk</artifactId>
@@ -68,6 +67,15 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-websocket</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.springframework.boot</groupId>
+			<artifactId>spring-boot-starter-aop</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>com.github.dadiyang</groupId>
+			<artifactId>autologging-aop</artifactId>
+			<version>1.0.0</version>
+		</dependency>
 
 		<dependency>
 			<groupId>io.springfox</groupId>
@@ -199,6 +207,7 @@
 			<version>5.2.0</version>
 			<scope>test</scope>
 		</dependency>
+
 	</dependencies>
 
 	<build>

+ 3 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/Application_ibms_data_sdk.java

@@ -5,9 +5,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import com.github.dadiyang.autologging.aop.annotation.EnableControllerLog;
+
 @SpringBootApplication
 @EnableScheduling
 @ServletComponentScan
+@EnableControllerLog
 public class Application_ibms_data_sdk {
 
 	public static void main(String[] args) throws Exception {

+ 28 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/WebServerConfiguration.java

@@ -0,0 +1,28 @@
+package com.persagy.ibms.data.sdk.service;
+
+import org.apache.catalina.connector.Connector;
+import org.apache.coyote.http11.Http11NioProtocol;
+import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
+import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
+import org.springframework.boot.web.server.ConfigurableWebServerFactory;
+import org.springframework.boot.web.server.WebServerFactoryCustomizer;
+import org.springframework.stereotype.Component;
+
+@Component
+public class WebServerConfiguration implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
+	@Override
+	public void customize(ConfigurableWebServerFactory configurableWebServerFactory) {
+		// 使用对应工厂类提供给我们的接口定制化我们的tomcat connector
+		((TomcatServletWebServerFactory) configurableWebServerFactory).addConnectorCustomizers(new TomcatConnectorCustomizer() {
+			@Override
+			public void customize(Connector connector) {
+				Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
+
+				// 定制化keepalivetimeout,设置30秒内没有请求则服务端自动断开keepalive链接
+				protocol.setKeepAliveTimeout(60000);
+				// 当客户端发送超过10000个请求则自动断开keepalive链接
+				protocol.setMaxKeepAliveRequests(1);
+			}
+		});
+	}
+}

+ 0 - 21
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -103,8 +103,6 @@ public class RestApi {
 
 	@PostMapping(path = { "/query", "/zkt-sdk/query" }, produces = "application/json;charset=UTF-8")
 	public String query(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || query: " + param);
 		String result = RestUtil.query(param);
 		return result;
 	}
@@ -116,7 +114,6 @@ public class RestApi {
 		ConcurrentHashMap<String, Date> param2time = RepositoryBase.ip2param2time.get(ip);
 		Date exist = param2time.putIfAbsent(param, new Date());
 		if (exist == null) {
-			log.info("ip:" + ip + " || post yes: " + param);
 			try {
 				Object resultObject = RestUtil.post(param);
 				String result = JSONObject.toJSONString(resultObject, SerializerFeature.WriteMapNullValue);
@@ -125,16 +122,12 @@ public class RestApi {
 				param2time.remove(param);
 			}
 		} else {
-			log.info("ip:" + ip + " || post no: " + param);
 			return null;
 		}
 	}
 
 	@PostMapping(path = { "/wrapper_post", "/zkt-sdk/wrapper_post" }, produces = "application/json;charset=UTF-8")
 	public String wrapper_post(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || wrapper_post : " + param);
-
 		JSONObject paramObject = JSON.parseObject(param);
 		String path = paramObject.get("path").toString();
 		Object Content = RestUtil.post(path);
@@ -146,56 +139,42 @@ public class RestApi {
 
 	@PostMapping(path = { "/post_filter_and_page", "/zkt-sdk/post_filter_and_page" }, produces = "application/json;charset=UTF-8")
 	public String post_filter_and_page(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || post_filter_and_page: " + param);
 		String result = RestUtil.post_filter_and_page(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/control", "/zkt-sdk/control" }, produces = "application/json;charset=UTF-8")
 	public String control(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || control: " + param);
 		String result = RestUtil.control(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/get_control_value", "/zkt-sdk/get_control_value" }, produces = "application/json;charset=UTF-8")
 	public String get_control_value(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || get_control_value: " + param);
 		String result = RestUtil.get_control_value(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/fjd_query", "/zkt-sdk/fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String fjd_query(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || fjd_query: " + param);
 		String result = RestUtil.fjd_query(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/history_fjd_query", "/zkt-sdk/history_fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String fjd_query_history(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || fjd_query_history: " + param);
 		String result = RestUtil.fjd_query_history(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/path_array_history_fjd_query", "/zkt-sdk/path_array_history_fjd_query" }, produces = "application/json;charset=UTF-8")
 	public String path_array_history_fjd_query(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || path_array_history_fjd_query: " + param);
 		String result = RestUtil.path_array_history_fjd_query(param);
 		return result;
 	}
 
 	@PostMapping(path = { "/getEquipStaticInfo", "/zkt-sdk/getEquipStaticInfo" }, produces = "application/json;charset=UTF-8")
 	public String getEquipStaticInfo(@RequestBody String param, HttpServletRequest request) {
-		String ip = RestUtil.getIp(request);
-		log.info("ip:" + ip + " || getEquipStaticInfo: " + param);
 		String result = RestUtil.getEquipStaticInfo(param).toJSONString();
 		return result;
 	}

+ 6 - 0
ibms-data-sdk/src/main/resources/application.properties

@@ -1,2 +1,8 @@
 server.port=8808
 spring.application.name=ibms-data-sdk
+
+autolog.app-name: ${spring.application.name}
+server.tomcat.accept-count: 1000
+server.tomcat.max-connections: 10000 
+server.tomcat.max-threads: 800 
+server.tomcat.min-spare-threads: 100