当前位置:网站首页>ss-5.consul服务端+生产者+消费者
ss-5.consul服务端+生产者+消费者
2022-08-03 05:09:00 【lhorse003】
服务器启动 localhost:8500 http://localhost/consumer/payment/consul – 消费者访问
服务器启动
consul agent -dev – 开发模式启动
cloud-providerconsul-payment8006
│ pom.xml
│
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─cmk
│ │ │ └─springCloud
│ │ │ │ PaymentMain8006.java //jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springCloud/PaymentMain8006.java:13:1
│ │ │ │
│ │ │ └─controller
│ │ │ PaymentController.java
│ │ │
│ │ └─resources
│ │ application.yml
│ │
│ └─test
│ └─java
pom.xml
<dependencies>
<!--SpringCloud consul-server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.cmk.springcoloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<!--SpringBoot整合web组件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--日常通用jar包配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
PaymentMain8006.java
@SpringBootApplication
@EnableDiscoveryClient
public class PaymentMain8006 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8006.class,args);
}
}
PaymentController.java
@RestController
@Slf4j
public class PaymentController {
@Value("${server.port}")
private String serverPort;
@RequestMapping("/payment/consul")
public String paymentConsul(){
return "springcloud with consul:"+serverPort+"\t"+ UUID.randomUUID().toString();
}
}
application.yml
server:
port: 8006
spring:
application:
name: consul-provider-payment
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${
spring.application.name}
cloud-providerconsul-payment8006
│ pom.xml
│
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─cmk
│ │ │ └─springcloud
│ │ │ │ OrderConsulMain80.java //jetbrains://idea/navigate/reference?project=zy2020&path=com/cmk/springcloud/OrderConsulMain80.java:14:1
│ │ │ │
│ │ │ ├─config
│ │ │ │ ApplicationContextConfig.java
│ │ │ │
│ │ │ └─controller
│ │ │ OrderConsulController.java
│ │ │
│ │ └─resources
│ │ application.yml
│ │
│ └─test
│ └─java
pom.xml
<dependencies>
<!--SpringCloud consul-server-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.cmk.springcoloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
OrderConsulMain80.java
@SpringBootApplication
@EnableDiscoveryClient //该注解用于向使用consul或者zookeeper作为注册中心时注册服务
public class OrderConsulMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderConsulMain80.class,args);
}
}
ApplicationContextConfig.java
@Configuration
public class ApplicationContextConfig {
@Bean
@LoadBalanced
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}
OrderConsulController.java
@RestController
@Slf4j
public class OrderConsulController {
public static final String INVOKE_URL = "http://consul-provider-payment";
@Resource
private RestTemplate restTemplate;
@GetMapping("/consumer/payment/consul")
public String paymentInfo() {
String result = restTemplate.getForObject(INVOKE_URL + "/payment/consul", String.class);
return result;
}
}
application.yml
###consuL服务端口号
server:
port: 80
spring:
application:
name: cloud-consumer-order
####consuL注册中心她址
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${
spring.application.name}
边栏推荐
- 信息编码、存储压缩与密码学
- 2. 两数相加
- 用户密码验证
- Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
- PotPlayer实现上班摸鱼电视自由
- Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
- How to prepare for the test interface test data
- typescript43-类型兼容性说明
- 力扣561. 数组拆分
- Interface testing framework of actual combat (2) | interface request assertion
猜你喜欢
多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG
Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
Harmony OS Date ano UI 】 【 】 the basic operation
测试人员的价值体现在哪里
unity2D横板游戏教程6-敌人AI以及受击动画
【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed
Object类与常用API
Kotlin-Flow常用封装类:StateFlow的使用
接口测试框架实战 | 流程封装与基于加密接口的测试用例设计
typescript47-函数之间的类型兼容性
随机推荐
安装IIS服务(Internet信息服务(Internet Information Services,简写IIS,互联网信息服务)
typescript44-对象之间的类兼容器
在树莓派上搭建属于自己的网页(2)
typescript39-class类的可见修饰符
获取Ip工具类
13.< tag-动态规划和回文字串>lt.647. 回文子串 + lt.516.最长回文子序列
Response 重写设置返回值
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
[Harmony OS] [ARK UI] ETS context basic operations
typescript45-接口之间的兼容性
Install PostgreSQL on Windows
Build your own web page on the Raspberry Pi (2)
closures in js
【Biotin Azide|cas:908007-17-0】Price_Manufacturer
接口测试框架实战(三)| JSON 请求与响应断言
UV decomposition of biotin - PEG2 - azide | CAS: 1192802-98-4 biotin connectors
Concepts and Methods of Exploratory Testing
Exception(异常) 和 Error(错误)区别解析
Apache DolphinScheduler版本2.0.5分布式集群的安装
Shell条件语句判断