Skip to content

Commit

Permalink
#3 修改部分配置文件,简化pom文件依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
lujun committed Dec 8, 2017
1 parent 7abfac0 commit 2d12a45
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 115 deletions.
38 changes: 8 additions & 30 deletions common-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
Expand All @@ -74,6 +45,13 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<!--使用这个包,尽量不要使用tomcat中自带的包,因为有些service会移除tomcat-->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 3 additions & 1 deletion common-service/src/main/java/demo/util/HttpUtil.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package demo.util;

import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

Expand All @@ -19,7 +21,7 @@ public class HttpUtil {
private static HttpHeaders getHeadersWithClientCredentials(String clientId, String secret) {
String plainClientCredentials = clientId + ":" + secret;
String base64ClientCredentials = new String(
org.apache.commons.codec.binary.Base64.encodeBase64(plainClientCredentials.getBytes()));
Base64.encodeBase64(plainClientCredentials.getBytes()));

HttpHeaders headers = getHeaders();
headers.add("Authorization", "Basic " + base64ClientCredentials);
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ account-service:
- DOCKER_IP=$DOCKER_IP
inventory-service:
image: ${IMAGE_PREFIX}inventory-service:${SKATE_VERSION}
ports:
- 8282:8282
links:
- neo4j
- discovery-service
Expand Down
6 changes: 3 additions & 3 deletions inventory-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public List<Inventory> getAvailableInventoryForProductIds(String productIds) {
.stream().collect(Collectors.toList());
}

@HystrixCommand(fallbackMethod = "getProductFallback")
public Inventory modifyProductNum(String productId, Long productNum) {
Long nowInventoryNum = Long.valueOf(getInventoryNumByPid(productId));
nowInventoryNum = nowInventoryNum > 0 ? nowInventoryNum : 0;
Expand Down
8 changes: 3 additions & 5 deletions inventory-service/src/main/java/demo/v1/ProductServiceV1.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package demo.v1;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import demo.inventory.Inventory;
import demo.product.Product;
import demo.product.ProductRepository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Stream;
import demo.product.Product;
import demo.product.ProductRepository;

/**
* Created by Thinkpad on 2017/11/24 0024.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

Expand Down
9 changes: 3 additions & 6 deletions inventory-service/src/main/java/demo/v1/StockServiceV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import demo.inventory.Inventory;
import demo.inventory.InventoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import util.JSONSerializer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Stream;

import demo.inventory.InventoryRepository;
import demo.stock.Stock;
import demo.stock.StockRepository;
import demo.util.JSONSerializer;

@Service
public class StockServiceV1 {
Expand All @@ -36,7 +35,6 @@ public StockServiceV1(StockRepository stockRepository,InventoryRepository invent
this.inventoryRepository = inventoryRepository;
}

@HystrixCommand(fallbackMethod = "getStockFeedBack")
public String getStockNoSync() {
List<Stock> stocks = stockRepository.getStockNoSync();
List<Map<String, Object>> stockList = new ArrayList<>();
Expand All @@ -54,7 +52,6 @@ public String getStockNoSync() {
return stockListstr;
}

@HystrixCommand(fallbackMethod = "getStockFeedBack")
public Stock modifyProductState(String productId) {
return stockRepository.modifyProductState(productId);
}
Expand Down
2 changes: 2 additions & 0 deletions inventory-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
server:
port: 8282
spring:
profiles:
active: test
Expand Down
56 changes: 18 additions & 38 deletions octopus-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
<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">
<parent>
<!--octopus-service不需要依赖父项目中的包,包有多余-->
<!--<parent>
<artifactId>event-sourcing</artifactId>
<groupId>com.dataman</groupId>
<version>master-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
</parent>-->

<modelVersion>4.0.0</modelVersion>

<groupId>com.dataman</groupId>
Expand All @@ -23,17 +25,24 @@
<spring-data-neo4j.version>4.0.0.RELEASE</spring-data-neo4j.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.8.RELEASE</version>
<relativePath/>
</parent>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -57,35 +66,6 @@
<artifactId>common-service</artifactId>
<version>master-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring-data-neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
1 change: 0 additions & 1 deletion octopus-service/src/main/java/demo/OctopusApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

Expand Down
6 changes: 2 additions & 4 deletions octopus-service/src/main/java/demo/job/ScanInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
import com.vip.saturn.job.SaturnJobExecutionContext;
import com.vip.saturn.job.SaturnJobReturn;

import org.apache.commons.lang.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.Date;

import demo.OctopusApplication;
import demo.service.StockService;
import demo.util.TimeUtil;

/**
* 定时扫描仓库 java job
Expand Down Expand Up @@ -51,7 +49,7 @@ public SaturnJobReturn handleJavaJob(final String jobName, final Integer shardIt
//查询未同步数据
String stocksStr = stockService.getStockNoSync();

log.info(String.format("扫描到进货商品:[%s] 时间:" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"),
log.info(String.format("扫描到进货商品:[%s] 时间:" + TimeUtil.ymdHms2str(),
stocksStr));
log.info("4:已经执行完成,开始返回执行结果 " + stocksStr + " ,并放入topic中...");
return new SaturnJobReturn(stocksStr);
Expand Down
11 changes: 3 additions & 8 deletions octopus-service/src/main/java/demo/service/StockService.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package demo.service;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -11,7 +10,6 @@
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -56,7 +54,7 @@ public StockService(RestTemplate restTemplate) {
private String oauthClientId;

@Value("${spring.application.oauthSecret}")
private static String oauthSecret;
private String oauthSecret;

@Value("${spring.application.passwordGrantStr}")
private String passwordGrantStr;
Expand Down Expand Up @@ -112,10 +110,7 @@ public String syncInventory(String kafkaMsg) {
//2:修改库存数量
this.modifyProductNum(productId, productNum);

log.info("同步商品编号为:" + productId + "数量为:" + productNum + "入库成功!" + DateFormatUtils.format(new
Date(),
"yyyy-MM-dd " +
"HH:mm:ss \n"), kafkaMsg);
log.info("同步商品编号为:" + productId + "数量为:" + productNum + "入库成功!" + TimeUtil.ymdHms2str(), kafkaMsg);
record.append("(编号为:" + productId + " 数量为:" + productNum + " )");
}
result = "同步商品:[" + record.toString() + "] 成功!" + TimeUtil.ymdHms2str();
Expand Down
8 changes: 4 additions & 4 deletions octopus-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
spring:
application:
remoteHost: 192.168.31.72
remotePort: 8787
remotePort: 8282
remoteAuthPort: 8181
remoteGetStockNoSyncUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/api/inventory/v1/stock/getStockNoSync
remoteModifyProductStateUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/api/inventory/v1/stock/modifyProductState/
remoteModifyInventoryNumUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/api/inventory/v1/modifyInventoryNum/
remoteGetStockNoSyncUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/v1/stock/getStockNoSync
remoteModifyProductStateUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/v1/stock/modifyProductState/
remoteModifyInventoryNumUrl: http://${spring.application.remoteHost}:${spring.application.remotePort}/v1/modifyInventoryNum/

oauthUserName: user
oauthPassword: password
Expand Down
12 changes: 5 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@
<docker.plugin.version>0.3.258</docker.plugin.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
Expand Down
Loading

0 comments on commit 2d12a45

Please sign in to comment.