Skip to content

Commit

Permalink
在hmily-demo-tac下,增加hmily-demo-tac-springcloud模块 (#358)
Browse files Browse the repository at this point in the history
* 完善tac demo, 增加基于SpringCloud的demo模块

* 在hmily-demo-tac-springcloud模块增加读已提交隔离级别的的测试案例
  • Loading branch information
zkyoma authored Jul 28, 2023
1 parent d1bee16 commit 339313e
Show file tree
Hide file tree
Showing 41 changed files with 3,276 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public interface PaymentService {
*/
void makePayment(Order order);


/**
* Test make payment.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017-2021 Dromara.org
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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>
<artifactId>hmily-demo-tac-springcloud</artifactId>
<groupId>org.dromara</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hmily-demo-tac-springcloud-account</artifactId>

<dependencies>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-demo-common</artifactId>
</dependency>

<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-tac-p6spy</artifactId>
<version>${hmily.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId></exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.dromara</groupId>
<artifactId>hmily-spring-boot-starter-springcloud</artifactId>
<version>${hmily.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId></exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</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-feign</artifactId>
</dependency>
-->

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
</exclusions>
</dependency>

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

<!-- if you want to use oracle,please import and open this-->
<!-- <dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
<scope>runtime</scope>
</dependency>-->
<!-- if you want to use postgresql,please import and open this-->
<!-- <dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1212</version>
</dependency>-->
<!-- if you want to use sqlserver,please import and open this-->
<!-- <dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>6.0</version>
</dependency>-->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
</dependencies>

<build>
<finalName>hmily-demo-springcloud-account</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>org.dromara.hmily.demo.springcloud.account.SpringCloudHmilyAccountApplication</mainClass>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2017-2021 Dromara.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dromara.hmily.demo.springcloud.account;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* The type SpringCloud tac account application.
*
* @author zhangzhi
*/
@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
@EnableTransactionManagement
@MapperScan("org.dromara.hmily.demo.common.account.mapper")
public class SpringCloudHmilyAccountApplication {

/**
* The entry point of application.
*
* @param args the input arguments
*/
public static void main(final String[] args) {
SpringApplication.run(SpringCloudHmilyAccountApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2017-2021 Dromara.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dromara.hmily.demo.springcloud.account.client;

import org.dromara.hmily.annotation.Hmily;
import org.dromara.hmily.demo.common.inventory.dto.InventoryDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* The interface Inventory client.
*
* @author zhangzhi
*/
@FeignClient(value = "inventory-service")
public interface InventoryClient {

/**
* 库存扣减.
*
* @param inventoryDTO 实体对象
* @return true 成功
*/
@RequestMapping("/inventory-service/inventory/decrease")
@Hmily
Boolean decrease(@RequestBody InventoryDTO inventoryDTO);

/**
* 模拟库存扣减异常.
*
* @param inventoryDTO 实体对象
* @return true 成功
*/
@Hmily
@RequestMapping("/inventory-service/inventory/mockWithTryException")
Boolean mockWithTryException(@RequestBody InventoryDTO inventoryDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2017-2021 Dromara.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.dromara.hmily.demo.springcloud.account.config;

import com.zaxxer.hikari.HikariDataSource;
import org.dromara.hmily.tac.p6spy.HmilyP6Datasource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
* The type Hmily tac datasource config.
*
* @author zhangzhi
*/
@Configuration
public class HmilyTacDatasourceConfig {

private final DataSourceProperties dataSourceProperties;

/**
* Instantiates a new Hmily tac datasource config.
*
* @param dataSourceProperties the data source properties
*/
public HmilyTacDatasourceConfig(final DataSourceProperties dataSourceProperties) {
this.dataSourceProperties = dataSourceProperties;
}

/**
* Data source data source.
*
* @return the data source
*/
@Bean
@Primary
public DataSource dataSource() {
HikariDataSource hikariDataSource = new HikariDataSource();
hikariDataSource.setJdbcUrl(dataSourceProperties.getUrl());
hikariDataSource.setDriverClassName(dataSourceProperties.getDriverClassName());
hikariDataSource.setUsername(dataSourceProperties.getUsername());
hikariDataSource.setPassword(dataSourceProperties.getPassword());
hikariDataSource.setMaximumPoolSize(20);
hikariDataSource.setMinimumIdle(10);
hikariDataSource.setConnectionTimeout(30000);
hikariDataSource.setIdleTimeout(600000);
hikariDataSource.setMaxLifetime(1800000);
return new HmilyP6Datasource(hikariDataSource);
}
}
Loading

0 comments on commit 339313e

Please sign in to comment.