java 微服务源码_java 微服务 入门级实例源码(基于SpringCloud)

本文提供了一个基于SpringCloud的Java微服务入门实例,包括服务注册中心EurekaServer、微服务提供者ProviderDemo和调用者CallerDemo。实例展示了服务器直接返回与调用微服务的性能对比,两者性能相近。
摘要由CSDN通过智能技术生成

【实例简介】

实例中包含三个项目 eurekaServer(服务注册中心),provicer_demo(微服务提供者),caller_demo(微服务调用者),并对 服务器直接返回与调用微服务的性能 进行了简单对比,两者相差不大

【实例截图】

下为调用方的 两个路由

508846e5f0dab8ecbf0ce4e69846e5ed.png

07582b1f4e00e27961c4117bd4154400.png

下为eurekaServer

0d67d1a3238ccc6a995a356b3053c800.png

8e85c1f99f9aefea9e8dc466511a096e.png

【核心代码】

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());

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值