文章目录
订单微服务
订单微服务的主要作用是从商品微服务中获取与订单相关的商品条目信息,进而完成对于订单数据的请求操作。
由于这里采用的是分布式的微服务架构,因而订单微服务中的商品条目信息是从两个商品微服务中以某种规则进行访问的,而这里,我们采用的是使用订单微服务以随机的方式访问不同的商品微服务。
springcloud-goods-order
springcloud-goods-order项目结构
springcloud-goods-order源码
OrderController源码:
package com.lyc.controller;
import com.lyc.order.entity.Order;
import com.lyc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class OrderController {
@Autowired
private OrderService orderService;
@GetMapping("order/{orderId}")
public Order queryOrderById(@PathVariable("orderId") String orderId){
return this.orderService.queryOrderById(orderId);
}
}
ItemFeignClient源码:
package com.lyc.feign;
import com.lyc.item.entity.Item;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(value = "springcloud-goods-item") //声明这是一个Feign的客户端
public interface ItemFeignClient {
@GetMapping("/item/{id}")
public Item queryItemById(@PathVariable("id") Long id);
}
OrderProperties源码:
package com.lyc.properties;
import com.lyc.order.entity.ItemProperties;
import lombok.*;
import org.springframework.boot.context