当前位置:网站首页>Microservice development steps (Nacos)
Microservice development steps (Nacos)
2022-07-01 14:30:00 【Whales are seen when the sea is blue-】

Other module Introduced in mall-common modular
Every Module They are connected to a database
1. Turn on nacos service

2. stay mall-commom Introduce dependency in
<!--1. First step : Registration discovery of service -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
3. in service ( Not common modular ) Of application.yml Configuration in file nacos The address of
spring:
# To configure Nacos Server Address and write application.name
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: mall-member
# Other services are configured separately name: mall-coupon、mall-member、mall-order、mall-product、mall-ware
4. Giving a Module Configure annotations on the startup class in @EnableDiscoveryClient
@SpringBootApplication
@EnableDiscoveryClient
public class MallMemberApplication {
public static void main(String[] args) {
SpringApplication.run(MallMemberApplication.class, args);
}
}
Through the above steps, you can nacos See the registered module

========================================================================
The next step is to use remote invocation to call methods from one service to another :Fegin Declarative remote call explain :mall-member The service wants to call mall-coupon service , Then in mall-member Add something to the service
5. stay mall-member Of pom.xml Introduce dependency in asking price
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
6. stay mall-coupon Write a method to prepare mall-member call
@RequestMapping("/member/list")
public R membercoupons() {
CouponEntity couponEntity = new CouponEntity();
couponEntity.setCouponName(" full 100 reduce 10");
return R.ok().put("coupons", Arrays.asList(couponEntity));
}
7. Write an interface , tell SpringCloud This interface needs to call the remote service
stay mall-member Write an interface in the module
@FeignClient("mall-coupon") // The name of the service called
public interface CouponFeginService {
// Which interface is used to write which
@RequestMapping("/coupon/coupon/member/list") // It says here that mall-coupon The complete request path of the interface in
public R membercoupons();
}
8. Turn on the function of remote call

@EnableFeignClients(basePackages = {
"com.eternal.mall.member.fegin"})
@SpringBootApplication
@EnableDiscoveryClient
public class MallMemberApplication {
public static void main(String[] args) {
SpringApplication.run(MallMemberApplication.class, args);
}
}
9. Start using

The above is the use of nacos Use as a registry
===================================================
The following uses nacos Manage the configuration information of each service as the configuration center
10. introduce Nacos Config Starter
Because every module can use , So put it directly on mall-common Module
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
11. Under each module that needs to be used /src/main/resources/bootstrap.properties Configuration in profile Nacos Config Metadata
spring.application.name=mall-coupon # Change according to the module name
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
12. Add a current service to the configuration center .properties Configuration file for
The default rules : Application name .properties
You can add any configuration data 
13. obtain nacos Profile data created in

边栏推荐
- Research Report on the development trend and competitive strategy of the global commercial glassware industry
- Guess lantern riddles, not programmers still can't understand?
- Websocket (simple experience version)
- Research Report on the development trend and competitive strategy of the global indexable milling cutter industry
- 【阶段人生总结】放弃考研,参与到工作中,已经顺利毕业了,昨天刚领毕业证
- 百度上找的期货公司安全吗?期货公司怎么确定正规
- Minimum spanning tree and bipartite graph in graph theory (acwing template)
- 被裁三個月,面試到處碰壁,心態已經開始崩了
- 【商业终端仿真解决方案】上海道宁为您带来Georgia介绍、试用、教程
- 光环效应——谁说头上有光的就算英雄
猜你喜欢

用对场景,事半功倍!TDengine 的窗口查询功能及使用场景全介绍

使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器

This paper introduces an implementation scheme to enhance the favorite transaction code management tool in SAP GUI

Buuctf reinforcement question ezsql

Oracle-数据库对象的使用

Realize queue with stack and stack with queue (C language \leetcode\u 232+225)

2022-2-15 learning the imitation Niuke project - Section 3 post details
![[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial](/img/44/b65aaf11b1e632f2dab55b6fc699f6.jpg)
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial
![[repair version] imitating the template of I love watching movies website / template of ocean CMS film and television system](/img/fa/15b1cc3a8a723ff34eb457af9f701e.jpg)
[repair version] imitating the template of I love watching movies website / template of ocean CMS film and television system

被裁三個月,面試到處碰壁,心態已經開始崩了
随机推荐
sqlilabs less-8
One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse
241. Design priorities for operational expressions
WebSocket(简单体验版)
TDengine 连接器上线 Google Data Studio 应用商店
Guess lantern riddles, not programmers still can't understand?
This paper introduces an implementation scheme to enhance the favorite transaction code management tool in SAP GUI
Research Report on the development trend and competitive strategy of the global axis measurement system industry
SWT/ANR问题--如何捕获性能的trace
Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
When the main process architecture game, to prevent calls everywhere to reduce coupling, how to open the interface to others to call?
Tdengine connector goes online Google Data Studio app store
Halo effect - who says that those with light on their heads are heroes
Oracle-数据库对象的使用
Basic operation of queue (implemented in C language)
2022. Let me take you from getting started to mastering jetpack architecture components - lifecycle
【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
C language ordering management system
MIT团队使用图神经网络,加速无定形聚合物电解质筛选,促进下一代锂电池技术开发
Research Report on development trend and competitive strategy of global vibration polishing machine industry