作者 朱兆平

测试 服务调用

... ... @@ -7,19 +7,32 @@ package com.tianbo.imfClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
@EnableScheduling
//@EnableEurekaClient
@EnableDiscoveryClient
@EnableTransactionManagement
@MapperScan("com.tianbo.imfClient.dao")
@ComponentScan({"com.tianbo.imfClient"})
public class ImfClientApplication {
public static void main(String[] args) {
SpringApplication.run(ImfClientApplication.class, args);
}
@Bean
@LoadBalanced
RestTemplate restTemplate(RestTemplateBuilder builder){
return builder.build();
}
}
... ...
package com.tianbo.imfClient;
package com.tianbo.imfClient.schedul;
import com.caac.imf.api.IMFClient;
import com.tianbo.imfClient.handle.IMFSaveHandle;
import com.tianbo.imfClient.schedul.IMF_Task;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestOperations;
@Component
public class IMF_Reader extends Thread{
protected static final Logger logger = Logger.getLogger(IMF_Reader.class);
private IMFClient client;
public static boolean isrunning;
protected IMF_Reader imf_reader;
@Autowired
private RestOperations restTemplate;
public IMF_Reader(IMFClient client) {
this.client = client;
}
@Override
public void run() {
try{
isrunning =true;
while(true) {
IMFClient client = IMF_Task.client;
if (null==restTemplate){
RestTemplateBuilder builder = new RestTemplateBuilder();
restTemplate = builder.build();
}
if (IMF_Task.LOGIN_OK) {
String message = this.client.getMSG();
String message = client.getMSG();
if (message != null) {
IMFSaveHandle imfSaveHandle = new IMFSaveHandle();
imfSaveHandle.handle(message);
//调用spring cloud 其他服务接口处理
restTemplate.put("http://fimsagentserver/msgAgent",message);
// IMFSaveHandle imfSaveHandle = new IMFSaveHandle();
// imfSaveHandle.handle(message);
}
} else {
... ...
package com.tianbo.imfClient;
package com.tianbo.imfClient.schedul;
import com.caac.imf.api.IMFClient;
import com.tianbo.imfClient.schedul.IMF_Task;
import com.tianbo.util.Date.DateUtil;
import com.tianbo.util.IO.FileTool;
import com.tianbo.util.XML.MakeImfMeta;
... ...
... ... @@ -2,13 +2,14 @@ package com.tianbo.imfClient.schedul;
import com.caac.imf.api.IMFClient;
import com.caac.imf.api.IMFClientFactory;
import com.tianbo.imfClient.IMF_Reader;
import com.tianbo.imfClient.IMF_Sender;
import com.tianbo.util.IO.FileTool;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestOperations;
import java.text.SimpleDateFormat;
@Component
... ... @@ -22,15 +23,29 @@ public class IMF_Task {
public static String loginpass;
public static String isNeedSend = "N";
@Autowired
private RestOperations restTemplate;
// @Scheduled(fixedRate = 5000)
public static void start() throws Exception {
@Scheduled(fixedRate = 5000)
public void start() throws Exception {
PropertyConfigurator.configure("config/log4j.properties");
client = IMFClientFactory.createInstance();
loginname= FileTool.readProperties("loginname");
loginpass= FileTool.readProperties("loginpass");
isNeedSend= FileTool.readProperties("isNeedSend");
logger.info(restTemplate);
restTemplate.put("http://fimsagentserver/msgAgent","<MSG>\n" +
"\t<META>\n" +
"\t\t<SNDR>FIMS</SNDR>\n" +
"\t\t<RCVR/>\n" +
"\t\t<SEQN>315756</SEQN>\n" +
"\t\t<DDTM>20190401020521</DDTM>\n" +
"\t\t<TYPE>DFOE</TYPE>\n" +
"\t\t<STYP>DFDL</STYP>\n" +
"\t</META>" +
"</MSG>");
//登录
if (!LOGIN_OK) {
... ... @@ -39,7 +54,7 @@ public class IMF_Task {
//启动读取线程
if (client != null) {
IMF_Reader reader = new IMF_Reader(client);
IMF_Reader reader = new IMF_Reader();
if (!IMF_Reader.isrunning) {
reader.start();
... ...
... ... @@ -9,10 +9,26 @@ web.upload-path=upload/
springboot.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,classpath:/templates/,file:${web.upload-path}
#springcloud 基本配置
#eureka主机名,会在控制页面中显示
spring.cloud.features.enabled=true
spring.cloud.discovery.enabled=true
spring.cloud.service-registry.auto-registration.enabled=true
eureka.instance.hostname=${spring.cloud.client.ip-address}
#eureka服务器页面中status的请求路径
eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index
#eureka注册中心服务器地址
eureka.client.service-url.defaultZone=http://127.0.0.1:19527/eureka/
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
eureka.client.registry-fetch-interval-seconds=30
eureka.instance.lease-renewal-interval-in-seconds=15
eureka.instance.lease-expiration-duration-in-seconds=45
#服务名
spring.application.name=tianbo.base.dev.devkit
spring.application.name=fimsAgentClient
spring.jackson.serialization.fail-on-empty-beans=false
... ... @@ -27,23 +43,6 @@ spring.jackson.default-property-inclusion=always
spring.mvc.view.suffix=.html
#springcloud 基本配置
#eureka主机名,会在控制页面中显示
spring.cloud.features.enabled=false
spring.cloud.discovery.enabled=false
spring.cloud.service-registry.auto-registration.enabled=false
#eureka.instance.hostname=${spring.cloud.client.ip-address}
#eureka服务器页面中status的请求路径
#eureka.instance.status-page-url=http://${eureka.instance.hostname}:${server.port}/index
#eureka注册中心服务器地址
#eureka.client.service-url.defaultZone=http://10.50.3.82:19527/eureka/
#eureka.instance.prefer-ip-address=true
#eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
#eureka.client.registry-fetch-interval-seconds=30
#eureka.instance.lease-renewal-interval-in-seconds=15
#eureka.instance.lease-expiration-duration-in-seconds=45
#spring.datasource oracle
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
... ...