{"id":13754158,"url":"https://github.com/jonsychen/microservices-examples","last_synced_at":"2025-05-09T22:31:12.923Z","repository":{"id":93966849,"uuid":"92480537","full_name":"jonsychen/microservices-examples","owner":"jonsychen","description":"基于Spring Boot/Spring Cloud 的微服务架构","archived":false,"fork":false,"pushed_at":"2017-06-06T07:27:19.000Z","size":372,"stargazers_count":33,"open_issues_count":0,"forks_count":13,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-03T09:06:55.595Z","etag":null,"topics":["microservice","spring-boot","spring-cloud"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonsychen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-26T06:43:22.000Z","updated_at":"2024-07-03T08:29:28.000Z","dependencies_parsed_at":"2023-03-19T18:07:13.366Z","dependency_job_id":null,"html_url":"https://github.com/jonsychen/microservices-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsychen%2Fmicroservices-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsychen%2Fmicroservices-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsychen%2Fmicroservices-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonsychen%2Fmicroservices-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonsychen","download_url":"https://codeload.github.com/jonsychen/microservices-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224884612,"owners_count":17386121,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["microservice","spring-boot","spring-cloud"],"created_at":"2024-08-03T09:01:45.730Z","updated_at":"2024-11-16T06:31:47.790Z","avatar_url":"https://github.com/jonsychen.png","language":"Java","readme":"# 基于Spring Boot/Spring Cloud 的微服务架构\n## 项目介绍\n### 预备知识\n+ \u003ca href=\"https://start.spring.io/\" target=\"_blank\"\u003e创建一个Spring Boot初始项目\u003c/a\u003e\n+ \u003ca href=\"https://springcloud.cc/\" target=\"_blank\"\u003eSpring Cloud 相关项目\u003c/a\u003e\n\n### 项目结构\n+ config : 配置文件仓库\n+ api-config : 配置管理中心\n+ api-registry : 服务注册中心\n+ api-gateway : 服务网关\n+ api-monitor : 服务监控中心\n+ api-service1 : 测试服务1\n+ api-service2 : 测试服务2\n\n### 项目架构\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/architecture.png)\n\n## RUN DEMO\n### 运行api-registry\n    访问地址：http://localhost:8761/\n![image](https://github.com/jonsychen/rest-security-demo/raw/master/etc/gettoken.png)\n### 运行api-config\n### 运行api-gateway\n### 运行api-service1,api-service2\n### 运行api-monitor\n### 运行结束后，配置中心如下：\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/registercenter.png)\n### 下面开始测试同步/异步接口，同步使用restful，异步使用基于rabbitmq的消息队列实现。\n### 示例1(同步)\n    1.使用postman通过网关访问service1提供的sayhi服务。\n\t2.网关收到请求后，解析请求的url，并匹配动态路由表，找到对应的服务名后向注册中心获取service1服务的当前运行的所有实例，再通过客服端负载均衡，将请求发送到指定的server1服务示例上。\n\t3.service1服务实例收到sayhi请求，同样经过客户端负载均衡后，调用service2服务的指定实例。\n\t4.service2服务实例收到sayhi请求，开始执行sayhi方法，打印并返回“hi from service2”。\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/service1_sayhi.png)\n\n### 示例2(异步)\n\t1.使用postman通过网关访问service1提供的send服务。\n\t2.网关收到请求后，解析请求的url，并匹配动态路由表，找到对应的服务名后向注册中心获取service1服务的当前运行的所有实例，再通过客服端负载均衡，将请求发送到指定的service1服务示例上。\n    3.service1服务实例收到send请求，接收请求参数，并将参数继续发送到指定的队列，等待其他服务处理后续操作，同步返回\"message has been sent successfully\"。\n\t4.service2监听指定队列，接收到待处理的消息，打印消息内容。\n\t5.service2处理完消息后，将处理结果发送到指定队列。\n\t6.service1监听指定结果通知队列，接收到待处理的消息，打印消息内容。\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/service1_send.png)\n\n### 示例3（实现动态配置的更改）\n    1.使用http get \"localhost:8881/author\", 来使用网关提供的打印author服务。\n\t2.网关收到打印author的请求，开始打印并返回author为\"Jonsy（author.name具体的值定义在配置文件中）。\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/gateway_author1.jpg)\n###\n\t3.修改配置仓库中service1-dev.properties中的author.name为\"frank\"。\n\t4.使用http post \"localhost:8881/bus/refresh?destination=gateway:**\",刷新服务名为gateway的所有服务实例。\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/gateway_author2.jpg)\n###\t\n\t5.再次使用http get \"localhost:8881/author\", 来使用网关提供的打印author服务。\n\t6.网关收到打印author的请求，开始打印并返回author为\"frank”（配置修改已生效）\n![image](https://github.com/jonsychen/microservices-examples/blob/master/etc/gateway_author3.jpg)\n\n\n### 需要注意的地方\n    1.这个架构使用rabbitmq作为消息总线，所以需要用户自行安装rabbitmq，并修改配置仓库中的相关配置。\n\t2.配置中心里面配置的仓库地址，需要修改为自己的仓库地址。\n\t3.IOC容器中的对象引用配置文件变量的时候，需要在类名上加上@RefreshScope来强制更新，否则动态修改的配置文件内容不会重新加载。\n\n## 联系我\n    Email: jonsychen@hotmail.com/i@jonsy.me\n    OICQ: 903352005\n    WeChat: Jonsychen_2013 \n","funding_links":[],"categories":["spring-cloud"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsychen%2Fmicroservices-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonsychen%2Fmicroservices-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonsychen%2Fmicroservices-examples/lists"}