SpringCloudAlibaba项目之生产者与消费者
SpringCloudAlibaba随笔目录
一、SpringCloudAlibaba项目之父工程搭建
二、SpringCloudAlibaba项目之Nacos搭建及服务注册
三、SpringCloudAlibaba项目之生产者与消费者
四、SpringCloudAlibaba项目之Ribbon负载均衡
五、SpringCloudAlibaba项目之OpenFeign远程调用
六、SpringCloudAlibaba项目之Nacos-config配置中心
七、SpringCloudAlibaba项目之Sentinel流量控制
八、SpringCloudAlibaba项目之Seata分布式事务
九、SpringCloudAlibaba项目之GateWay网关
十、SpringCloudAlibaba项目之SkyWalking链路跟踪
SpringCloudAlibaba项目之生产者与消费者
1、生产者与消费者
本篇文章,我们搭建俩个服务,生产者服务与消费者服务。
我们以电商系统为例:服务生产者service-order,
服务消费者service-stock
说明:service-order 作为消费者提供新增订单信息的功能,service-stock作为生产者提供库存的扣减服务功能;这里调用者为消费者,被掉用者为生产者。
项目目录
2、生产者服务搭建
使用Spring Initializr创建
修改pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- 继承父工程版本依赖 --> <parent> <artifactId>spring-cloud-alibaba</artifactId> <groupId>com.qt</groupId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.qt</groupId> <artifactId>service-stock</artifactId> <version>0.0.1-SNAPSHOT</version> <name>service-stock</name> <description>service-stock project for Spring Boot</description> <dependencies> <!-- springweb 启动依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- nacos 服务注册发现(客户端)依赖 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- springboot 测试类 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.3.7.RELEASE</version> <configuration> <mainClass>com.qt.servicestock.ServiceStockApplication</mainClass> </configuration> <executions> <execution> <id>repackage</id> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>