Skip to content

Commit 288d590

Browse files
author
wuxw7
committed
日志服务 编码生成服务测试通过
1 parent 12b3cd9 commit 288d590

File tree

29 files changed

+445
-75
lines changed

29 files changed

+445
-75
lines changed

CenterService/src/main/java/com/java110/center/smo/impl/CenterServiceSMOImpl.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.java110.common.cache.MappingCache;
99
import com.java110.common.constant.*;
1010
import com.java110.common.exception.*;
11+
import com.java110.common.factory.ApplicationContextFactory;
1112
import com.java110.common.kafka.KafkaFactory;
1213
import com.java110.common.log.LoggerEngine;
1314
import com.java110.common.util.*;
@@ -23,6 +24,7 @@
2324
import com.java110.event.center.DataFlowEventPublishing;
2425

2526
import com.java110.log.agent.LogAgent;
27+
import com.java110.service.init.ServiceInfoListener;
2628
import com.java110.service.smo.IQueryServiceSMO;
2729
import org.apache.commons.lang3.math.NumberUtils;
2830
import org.springframework.beans.factory.annotation.Autowired;
@@ -508,7 +510,9 @@ private void transferInvokeBusinessSystem(DataFlow dataFlow) throws BusinessExce
508510
dataFlow.setResData(responseJson);
509511

510512
DataFlowFactory.addCostTime(dataFlow,dataFlow.getCurrentBusiness().getServiceCode(), "调用"+dataFlow.getCurrentBusiness().getServiceCode()+"耗时", startDate);
511-
saveLogMessage(dataFlow.getCurrentBusiness().getTransferData(),dataFlow.getResData());
513+
saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getCurrentBusiness().getTransferData()),
514+
LogAgent.createLogMessage(dataFlow.getResponseCurrentHeaders(),dataFlow.getResData()),
515+
DateUtil.getCurrentDate().getTime()-startDate.getTime());
512516

513517

514518
DataFlowFactory.addCostTime(dataFlow, "invokeBusinessSystem", "调用下游系统耗时", startDate);
@@ -776,6 +780,11 @@ private void reloadOrderInfoAndConfigData(DataFlow dataFlow) {
776780
if("-1".equals(dataFlow.getDataFlowId()) || StringUtil.isNullOrNone(dataFlow.getDataFlowId())){
777781
throw new InitConfigDataException(ResponseConstant.RESULT_CODE_ERROR,"请求报文中没有包含 dataFlowId 节点");
778782
}
783+
//重新刷端口信息
784+
ServiceInfoListener serviceInfoListener = ApplicationContextFactory.getBean("serviceInfoListener",ServiceInfoListener.class);
785+
if(serviceInfoListener != null){
786+
dataFlow.setPort(serviceInfoListener.getServerPort()+"");
787+
}
779788
//重新加载配置
780789
initConfigData(dataFlow);
781790
}
@@ -1164,7 +1173,8 @@ private void doAsynchronousBusinesses(DataFlow dataFlow) throws BusinessExceptio
11641173
dataFlow.setResponseBusinessJson(DataTransactionFactory.createOrderResponseJson(dataFlow.getTransactionId(),
11651174
ResponseConstant.RESULT_CODE_SUCCESS, "成功"));
11661175
DataFlowFactory.addCostTime(dataFlow, "doSynchronousBusinesses", "异步调用业务系统总耗时", startDate);
1167-
saveLogMessage(dataFlow,dataFlow.getRequestBusinessJson(),dataFlow.getResponseBusinessJson(),
1176+
saveLogMessage(dataFlow,LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getRequestBusinessJson().toJSONString()),
1177+
LogAgent.createLogMessage(dataFlow.getRequestCurrentHeaders(),dataFlow.getResponseBusinessJson().toJSONString()),
11681178
DateUtil.getCurrentDate().getTime()-startDate.getTime());
11691179
}
11701180

CodeService/doc/start_codeService.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#### debug model prod
3+
#nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar -Dspring.profiles.active=dev CodeService.jar $1 > code.log 2>&1 &
4+
5+
#### normal prod model
6+
#nohup java -jar -Dspring.profiles.active=prod $1 CodeService.jar > code.log $1 2>&1 &
7+
8+
#### normal test model
9+
#nohup java -jar -Dspring.profiles.active=test $1 CodeService.jar > code.log $1 2>&1 &
10+
11+
#### normal dev model
12+
nohup java -jar -Dspring.profiles.active=dev $1 CodeService.jar > code.log $1 2>&1 &
13+
14+
tail -100f code.log

CodeService/pom.xml

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
</dependencies>
3030

3131
<build>
32+
<finalName>CodeService</finalName>
3233
<plugins>
3334
<plugin>
3435
<groupId>org.apache.maven.plugins</groupId>
@@ -56,6 +57,14 @@
5657
</execution>
5758
</executions>
5859
</plugin>
60+
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
<configuration>
65+
<mainClass>com.java110.code.CodeServiceApplicationStart</mainClass>
66+
</configuration>
67+
</plugin>
5968
</plugins>
6069
</build>
6170
</project>

CodeService/src/main/java/com/java110/CodeServiceApplicationStart.java CodeService/src/main/java/com/java110/code/CodeServiceApplicationStart.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.java110;
1+
package com.java110.code;
22

33
/**
44
* Hello world!
@@ -8,7 +8,6 @@
88
import com.java110.common.exception.StartException;
99
import com.java110.common.factory.ApplicationContextFactory;
1010
import com.java110.common.util.Assert;
11-
import com.java110.common.util.DateUtil;
1211
import com.java110.common.util.StringUtil;
1312
import com.java110.config.properties.code.ZookeeperProperties;
1413
import com.java110.service.init.ServiceInfoListener;
@@ -17,17 +16,11 @@
1716
import org.apache.zookeeper.data.Stat;
1817
import org.springframework.boot.SpringApplication;
1918
import org.springframework.boot.autoconfigure.SpringBootApplication;
20-
import org.springframework.boot.web.client.RestTemplateBuilder;
2119
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
22-
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
2320
import org.springframework.context.ApplicationContext;
24-
import org.springframework.context.annotation.Bean;
25-
import org.springframework.http.converter.StringHttpMessageConverter;
26-
import org.springframework.web.client.RestTemplate;
2721

2822
import java.net.InetAddress;
2923
import java.net.UnknownHostException;
30-
import java.nio.charset.Charset;
3124
import java.util.List;
3225

3326
/**

CodeService/src/main/java/com/java110/code/api/CodeApi.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
import com.java110.core.factory.DataTransactionFactory;
1313
import com.java110.feign.code.ICodeApi;
1414
import org.springframework.beans.factory.annotation.Autowired;
15-
import org.springframework.web.bind.annotation.RequestBody;
16-
import org.springframework.web.bind.annotation.RequestMapping;
17-
import org.springframework.web.bind.annotation.RequestMethod;
18-
import org.springframework.web.bind.annotation.RestController;
15+
import org.springframework.web.bind.annotation.*;
1916

2017
import javax.servlet.http.HttpServletRequest;
2118
import java.util.HashMap;
@@ -100,7 +97,8 @@ public void setPrimaryKeyServiceSMOImpl(IPrimaryKeyServiceSMO primaryKeyServiceS
10097
* @return
10198
*/
10299
@Override
103-
public String generateCode(String prefix) {
100+
@RequestMapping(value = "/codeApi/generateCode",method = RequestMethod.POST)
101+
public String generateCode(@RequestParam("prefix") String prefix) {
104102

105103
try {
106104
JSONObject requestInfo = new JSONObject();
@@ -114,7 +112,7 @@ public String generateCode(String prefix) {
114112
primaryKeyServiceSMOImpl.generateCode(dataFlow);
115113

116114
if (!ResponseConstant.RESULT_CODE_SUCCESS.equals(dataFlow.getResJson().getString("code"))) {
117-
throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成oId编码失败 "
115+
throw new ResponseErrorException(ResponseConstant.RESULT_CODE_ERROR, "生成编码失败 "
118116
+ dataFlow.getResJson().getString("message"));
119117
}
120118

LogService/doc/start_logService.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
#### debug model prod
3+
#nohup java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n -jar -Dspring.profiles.active=dev LogService.jar $1 > log.log 2>&1 &
4+
5+
#### normal prod model
6+
#nohup java -jar -Dspring.profiles.active=prod $1 LogService.jar > log.log $1 2>&1 &
7+
8+
#### normal test model
9+
#nohup java -jar -Dspring.profiles.active=test $1 LogService.jar > log.log $1 2>&1 &
10+
11+
#### normal dev model
12+
nohup java -jar -Dspring.profiles.active=dev $1 LogService.jar > log.log $1 2>&1 &
13+
14+
tail -100f log.log

LogService/src/main/java/com/java110/log/LogServiceApplicationStart.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.boot.SpringApplication;
99
import org.springframework.boot.autoconfigure.SpringBootApplication;
1010
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
11+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
1112
import org.springframework.context.ApplicationContext;
1213

1314
/**
@@ -19,8 +20,10 @@
1920
* @date 2016年8月6日
2021
* @tag
2122
*/
22-
@SpringBootApplication(scanBasePackages = {"com.java110.service","com.java110.log","com.java110.core","com.java110.cache"})
23+
@SpringBootApplication(scanBasePackages = {"com.java110.service","com.java110.log",
24+
"com.java110.feign.code","com.java110.core","com.java110.cache"})
2325
@EnableDiscoveryClient
26+
@EnableFeignClients(basePackages = {"com.java110.feign.code"})
2427
public class LogServiceApplicationStart {
2528

2629

LogService/src/main/java/com/java110/log/kafka/LogServiceKafka.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class LogServiceKafka extends BaseController {
4444
@Autowired
4545
private ILogServiceSMO logServiceSMOImpl;
4646

47-
@KafkaListener(topics = {KafkaConstant.TOPIC_LOG_NAME})
47+
@KafkaListener(topics = {"LOG"})
4848
public void listen(ConsumerRecord<?, ?> record) {
4949
logger.info("LogServiceKafka receive message: {}", record.value().toString());
5050
String logMessage = record.value().toString();

LogService/src/main/java/com/java110/log/smo/impl/LogServiceSMOImpl.java

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.java110.common.util.DateUtil;
88
import com.java110.core.base.smo.BaseServiceSMO;
99
import com.java110.core.factory.GenerateCodeFactory;
10+
import com.java110.feign.code.ICodeApi;
1011
import com.java110.log.dao.LogServiceDao;
1112
import com.java110.log.smo.ILogServiceSMO;
1213
import org.slf4j.Logger;
@@ -31,6 +32,9 @@ public class LogServiceSMOImpl extends BaseServiceSMO implements ILogServiceSMO
3132

3233
private final static Logger logger = LoggerFactory.getLogger(LogServiceSMOImpl.class);
3334

35+
@Autowired
36+
private ICodeApi codeApi;
37+
3438
@Autowired
3539
private LogServiceDao logServiceDaoImpl;
3640

@@ -62,6 +66,7 @@ private void doSaveLogMessage(String logMessage) throws Exception {
6266

6367
// 调用服务生成log_id
6468
String log_id = GenerateCodeFactory.getInnerTransactionId();
69+
//String log_id = codeApi.generateCode("1000001");
6570

6671
// 封装日志保存参数
6772
Map logMessageParams= new HashMap();
@@ -95,6 +100,8 @@ private void builderLogMessageParams(Map logMessageParams,JSONObject logMessageO
95100
logMessageParams.put("responseMessage",responseMessageObj.getString("body"));
96101

97102
logMessageParams.put("timestamp", DateUtil.getDefaultDateFromString(logMessageObj.getString("timestamp")));
103+
104+
logMessageParams.put("month",DateUtil.getCurrentMonth());
98105
}
99106

100107
/**
@@ -122,6 +129,13 @@ private void validateLogMessage(JSONObject logMessageObj){
122129
Assert.hasKey(logMessageObj,"responseMessage","can not find responseMessage node ");
123130
}
124131

132+
public ICodeApi getCodeApi() {
133+
return codeApi;
134+
}
135+
136+
public void setCodeApi(ICodeApi codeApi) {
137+
this.codeApi = codeApi;
138+
}
125139

126140
public LogServiceDao getLogServiceDaoImpl() {
127141
return logServiceDaoImpl;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
jedis:
2+
pool:
3+
config:
4+
maxTotal: 100
5+
maxIdle: 20
6+
maxWaitMillis: 20000
7+
host: 192.168.31.199
8+
port: 6379
9+
10+
eureka:
11+
instance:
12+
leaseRenewalIntervalInSeconds: 10
13+
leaseExpirationDurationInSeconds: 30
14+
client:
15+
serviceUrl:
16+
defaultZone: http://192.168.31.199:8761/eureka/
17+
#defaultZone: http://localhost:8761/eureka/
18+
server:
19+
port: 8004
20+
tomcat:
21+
uri-encoding: UTF-8
22+
23+
spring:
24+
http:
25+
encoding:
26+
charset: UTF-8
27+
enabled: true
28+
force: true
29+
application:
30+
name: log-service
31+
redis:
32+
database: 0
33+
host: 192.168.31.199
34+
port: 6379
35+
pool:
36+
max-active: 300
37+
max-wait: 10000
38+
max-idle: 100
39+
min-idle: 0
40+
timeout: 0
41+
datasource:
42+
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
43+
minIdle: 5
44+
validationQuery: SELECT 1 FROM DUAL
45+
initialSize: 5
46+
maxWait: 60000
47+
filters: stat,wall,log4j
48+
poolPreparedStatements: true
49+
type: com.alibaba.druid.pool.DruidDataSource
50+
url: jdbc:mysql://192.168.31.199:3306/TT?useUnicode=true&characterEncoding=utf-8
51+
maxPoolPreparedStatementPerConnectionSize: 20
52+
password: TT@12345678
53+
testOnBorrow: false
54+
testWhileIdle: true
55+
minEvictableIdleTimeMillis: 300000
56+
timeBetweenEvictionRunsMillis: 60000
57+
testOnReturn: false
58+
driverClassName: com.mysql.jdbc.Driver
59+
maxActive: 20
60+
username: TT
61+
62+
#============== kafka ===================
63+
kafka:
64+
consumer:
65+
zookeeper:
66+
connect: 192.168.31.199:2181
67+
servers: 192.168.31.199:9092
68+
enable:
69+
auto:
70+
commit: true
71+
session:
72+
timeout: 6000
73+
auto:
74+
commit:
75+
interval: 100
76+
offset:
77+
reset: latest
78+
topic: test
79+
group:
80+
id: logService
81+
concurrency: 10
82+
83+
producer:
84+
zookeeper:
85+
connect: 192.168.31.199:2181
86+
servers: 192.168.31.199:9092
87+
retries: 0
88+
batch:
89+
size: 4096
90+
linger: 1
91+
buffer:
92+
memory: 40960

0 commit comments

Comments
 (0)