在安装完基础设施后启动MySQL, Kafka, Redis后开始启动后端项目。
client-service(port: 8087)
Download executable jar file: client-service-0.0.1-SNAPSHOT.jar
C:\Program Files\Java\jdk-11\bin>java -version
java version "11.0.18" 2023-01-17 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.18+9-LTS-195, mixed mode)
C:\Program Files\Java\jdk-11\bin>java -jar D:\SDisk\workspace\Java\client-service\target\client-service-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.8)
2023-03-06 21:43:14.609 INFO 540 --- [ main] c.e.c.ClientServiceApplication : Starting ClientServiceApplication v0.0.1-SNAPSHOT using Java 11.0.18 on DESKTOP-VG9BSQR with PID 540 (D:\SDisk\workspace\Java\client-service\target\client-service-0.0.1-SNAPSHOT.jar started by syq in C:\Program Files\Java\jdk-11\bin)
2023-03-06 21:43:14.612 INFO 540 --- [ main] c.e.c.ClientServiceApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-06 21:43:15.176 INFO 540 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-03-06 21:43:15.224 INFO 540 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 37 ms. Found 1 JPA repository interfaces.
2023-03-06 21:43:15.873 INFO 540 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2023-03-06 21:43:15.884 INFO 540 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-06 21:43:15.884 INFO 540 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-06 21:43:15.971 INFO 540 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-06 21:43:15.971 INFO 540 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1302 ms
2023-03-06 21:43:16.002 INFO 540 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-03-06 21:43:16.222 INFO 540 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-03-06 21:43:16.234 INFO 540 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
2023-03-06 21:43:16.376 INFO 540 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-03-06 21:43:16.431 INFO 540 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.14.Final
2023-03-06 21:43:16.602 INFO 540 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2023-03-06 21:43:16.723 INFO 540 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2023-03-06 21:43:17.215 INFO 540 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-03-06 21:43:17.244 INFO 540 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-03-06 21:43:17.503 WARN 540 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-03-06 21:43:17.884 INFO 540 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8087 (http) with context path ''
2023-03-06 21:43:17.892 INFO 540 --- [ main] c.e.c.ClientServiceApplication : Started ClientServiceApplication in 3.759 seconds (JVM running for 4.217)
bwic-service(port: 8086)
Download executable jar file: bwic-service-0.0.1-SNAPSHOT.jar
C:\Program Files\Java\jdk-11\bin>java -version
java version "11.0.18" 2023-01-17 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.18+9-LTS-195)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.18+9-LTS-195, mixed mode)
C:\Program Files\Java\jdk-11\bin>java -jar D:\SDisk\workspace\Java\bwic-service\target\bwic-service-0.0.1-SNAPSHOT.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.8)
2023-03-06 21:50:32.676 INFO 13044 --- [ main] c.e.bwicservice.BwicServiceApplication : Starting BwicServiceApplication v0.0.1-SNAPSHOT using Java 11.0.18 on DESKTOP-VG9BSQR with PID 13044 (D:\SDisk\workspace\Java\bwic-service\target\bwic-service-0.0.1-SNAPSHOT.jar started by syq in C:\Program Files\Java\jdk-11\bin)
2023-03-06 21:50:32.678 INFO 13044 --- [ main] c.e.bwicservice.BwicServiceApplication : No active profile set, falling back to 1 default profile: "default"
2023-03-06 21:50:33.203 INFO 13044 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-03-06 21:50:33.245 INFO 13044 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 35 ms. Found 2 JPA repository interfaces.
2023-03-06 21:50:33.863 INFO 13044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8086 (http)
2023-03-06 21:50:33.873 INFO 13044 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2023-03-06 21:50:33.873 INFO 13044 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2023-03-06 21:50:33.945 INFO 13044 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2023-03-06 21:50:33.945 INFO 13044 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1220 ms
2023-03-06 21:50:34.019 INFO 13044 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2023-03-06 21:50:34.333 INFO 13044 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2023-03-06 21:50:34.426 INFO 13044 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-03-06 21:50:34.474 INFO 13044 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.14.Final
2023-03-06 21:50:34.625 INFO 13044 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2023-03-06 21:50:34.712 INFO 13044 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
2023-03-06 21:50:35.181 INFO 13044 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-03-06 21:50:35.188 INFO 13044 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-03-06 21:50:35.530 WARN 13044 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2023-03-06 21:50:35.826 INFO 13044 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8086 (http) with context path ''
2023-03-06 21:50:35.833 INFO 13044 --- [ main] c.e.bwicservice.BwicServiceApplication : Started BwicServiceApplication in 3.542 seconds (JVM running for 3.928)
- Run SQL to add bwic
- 进入容器
docker exec -it mysql-test bash
- 连接 MySQL
mysql -h localhost -u root -p
输入密码 use bwic;
- 执行 SQL ```mysql-sql alter table bwic modify id int(11) auto_increment; delete from bwic; Insert into bwic(id, cusip, position, price, due_date, market_value, created_by, created_date) values (1, ‘037833100’, 20, 100.0, ‘20230222’, 1500, ‘Nicole Montgomery[trader]’, ‘2023-02-10 11:12:12’), (2, ‘02079K107’, 30, 70.0, ‘20230222’, 1800, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (3, ‘011659109’, 10, 80.0, ‘20230221’, 500, ‘Nicole Montgomery[trader]’, ‘2023-02-10 11:12:12’), (4, ‘931142103’, 60, 40.0, ‘20230221’, 1200, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (5, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (6, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (7, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (8, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (9, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (10, ‘G3921A955’, 80, 90.0, ‘20230820’, 5000, ‘Susan Wagner[trader]’, ‘2023-02-10 11:12:12’), (11, ‘G3930E101’, 100, 10.0, ‘20230920’, 300, ‘Nicole Montgomery[trader]’, ‘2023-02-10 11:12:12’);
- 进入容器
alter table bid modify id int(11) auto_increment; delete from bid;
## audit-service(port: 8000)
1. 创建环境
```shell
conda create -n py39 python==3.9
- 激活环境
conda activate py39
- 安装包
pip install fastapi pip install "uvicorn[standard]" pip install redis pip install confluent_kafka
- 执行
(py39) D:\SDisk\workspace\Python\bwic-audit>python main.py Kafka Consumer has been initiated... Available topics to consume: {'machine-test': TopicMetadata(machine-test, 1 partitions), 'bid-topic': TopicMetadata(bid-topic, 1 partitions), 'quickstart': TopicMetadata(quickstart, 1 partitions), '__consumer_offsets': TopicMetadata(__consumer_offsets, 50 partitions), 'cancel-topic': TopicMetadata(cancel-topic, 1 partitions)} [32mINFO[0m: Will watch for changes in these directories: ['D:\\SDisk\\workspace\\Python\\bwic-audit'] [32mINFO[0m: Uvicorn running on [1mhttp://0.0.0.0:8000[0m (Press CTRL+C to quit) [32mINFO[0m: Started reloader process [[36m[1m3164[0m] using [36m[1mWatchFiles[0m Kafka Consumer has been initiated... Available topics to consume: {'machine-test': TopicMetadata(machine-test, 1 partitions), 'bid-topic': TopicMetadata(bid-topic, 1 partitions), 'quickstart': TopicMetadata(quickstart, 1 partitions), '__consumer_offsets': TopicMetadata(__consumer_offsets, 50 partitions), 'cancel-topic': TopicMetadata(cancel-topic, 1 partitions)} Kafka Consumer has been initiated... Available topics to consume: {'machine-test': TopicMetadata(machine-test, 1 partitions), 'bid-topic': TopicMetadata(bid-topic, 1 partitions), 'quickstart': TopicMetadata(quickstart, 1 partitions), '__consumer_offsets': TopicMetadata(__consumer_offsets, 50 partitions), 'cancel-topic': TopicMetadata(cancel-topic, 1 partitions)} [32mINFO[0m: Started server process [[36m8548[0m] [32mINFO[0m: Waiting for application startup. [32mINFO[0m: Application startup complete.
API sample
- Login: http://localhost:8086/client/login/1
- List: http://localhost:8086/bwic/list/5
- MyList: http://localhost:8086/bwic/mylist/5
- Bid: http://localhost:8086/bwic/bid
{ "bwicId": 11, "clientId": 5, "bidMarketValue": 200 }
- Cancel: http://localhost:8086/bwic/cancel
{ "bwicId": 11, "clientId": 5 }