【实例简介】
实例中包含三个项目 eurekaServer(服务注册中心),provicer_demo(微服务提供者),caller_demo(微服务调用者),并对 服务器直接返回与调用微服务的性能 进行了简单对比,两者相差不大
【实例截图】
下为调用方的 两个路由
下为eurekaServer
【核心代码】
package com.example.service_caller_demo.controller;
import com.example.service_caller_demo.feignclient.SayHelloCaller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller
public class Home {
@Autowired
private SayHelloCaller caller;
@RequestMapping("/sayHello")
@ResponseBody
public String sayHello(){
return caller.sayHello();
}
@RequestMapping("/hello")
@ResponseBody
public String hello(){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
return "我是来自caller的服务端,你好呀!" sdf.format(new Date());
}
}