Spring cloud:服务调用-声明式客户端访问
2021-02-10 16:19
标签:order pos not tool datetime mys 搭建 负载 test 通过声明式客户端 openfeign 进行支付微服务的访问。 只需要修改支付服务调用层,增加依赖就可以了。 只需要定义接口,不需要进行实现。 使用 curl 命令访问订单微服务,查看返回,如果返回的订单已支付,则表示通过声明式客户端访问成功。 默认也是具有负载均衡的。 Spring cloud:服务调用-声明式客户端访问 标签:order pos not tool datetime mys 搭建 负载 test 原文地址:https://www.cnblogs.com/jiangbo44/p/12734052.html环境
背景
搭建步骤
支付服务调用层
package jiangbo.springcloud.dao;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import jiangbo.springcloud.dao.dto.PaymentRequest;
import jiangbo.springcloud.dao.dto.PaymentResponse;
@FeignClient("payment")
public interface PaymentDao {
@PostMapping("/payment")
PaymentResponse payment(PaymentRequest paymentRequest);
}
启动类
package jiangbo.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
public class JiangBoApplication {
public static void main(String[] args) {
SpringApplication.run(JiangBoApplication.class, args);
}
}
pom.xml
验证
curl -H "Content-Type: application/json" -X POST --data ‘{"name":"jiangbo11","amount":"8.99"}‘, http://localhost:4410/order/payment
{"id":12,"name":"jiangbo11","amount":"8.99","status":"PAID","createTime":1587304461000,"updateTime":1587304462000}
上一篇:5.线性回归算法
文章标题:Spring cloud:服务调用-声明式客户端访问
文章链接:http://soscw.com/index.php/essay/53647.html