当前位置: 首页 > news >正文

中国纳溪门户网站建设项目环境影响宁波seo怎么推广

中国纳溪门户网站建设项目环境影响,宁波seo怎么推广,公司建站文案给网站公司看的,设计上海兼职网站建设这是本人学习的总结,主要学习资料如下 马士兵教育 目录1、Spring Cloud 简介2、Eureka3、建立Spring Cloud项目3.1、启动Server3.1.1、dependency3.1.2、配置文件3.1.3、Server端启动代码3.2、启动Client3.2.1、dependency3.2.2、配置文件3.3.3、Client端启动代码3…

这是本人学习的总结,主要学习资料如下

  • 马士兵教育

目录

  • 1、Spring Cloud 简介
  • 2、Eureka
  • 3、建立Spring Cloud项目
    • 3.1、启动Server
      • 3.1.1、dependency
      • 3.1.2、配置文件
      • 3.1.3、Server端启动代码
    • 3.2、启动Client
      • 3.2.1、dependency
      • 3.2.2、配置文件
      • 3.3.3、Client端启动代码
    • 3.3、服务之间获取信息

1、Spring Cloud 简介

spring cloud是为了解决微服务架构的难题而诞生的微服务全家桶框架。

确定spring cloud的版本,要根据spring boot来确定,官网上有对应的表格。

注意下面的提示,Dalston, Edgware, Finchley, Greenwich已经不再维护,所以实际开发中不要再使用这四个spring cloud的版本。

在这里插入图片描述

https://spring.io/projects/spring-cloud

2、Eureka

EurekaSpringCloud Nexflix的核心子模块,其中包含ServerClient

Server提供服务注册,存储所有可用服务节点。

Client用于简化和Server的通讯复杂度

下面是Eureka的简单架构图

在这里插入图片描述

每一个服务节点需要在Eureka Server中注册,如果需要其他节点的服务,则需要远程调用Service ProviderProvider会访问Server,由Server找到一个合适的节点提供服务给cumsumer

3、建立Spring Cloud项目

接下来就是代码展示如何配置启动serverclient,以及client之间获取信息

3.1、启动Server

3.1.1、dependency

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.3.7.RELEASE</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Hoxton.SR12</version><type>pom</type><scope>import</scope></dependency>
</dependencies>

3.1.2、配置文件

spring:application:name: msb-eureka-server
server:port: 8761eureka:instance:#注册实例名称hostname: localhost#是否将自己的ip注册到eureka中,默认false 注册 主机名prefer-ip-address: true# Eureka客户端需要多长时间发送心跳给Eureka,表明他仍然或者,默认是30# 通过下面方式我们可以设置,默认单位是秒lease-renewal-interval-in-seconds: 10# Eurkea服务器在接受到实例最后一次发送的心跳后,需要等待多久可以将次实例删除# 默认值是90# 通过下面方式我们可以设置,默认单位是秒lease-expiration-duration-in-seconds: 30client:#是否注册到eureka服务中register-with-eureka: false#是否拉取其他服务fetch-registry: false

3.1.3、Server端启动代码

@EnableEurekaServer
@SpringBootApplication
public class EureakServerApplication {public static void main(String[] args) {SpringApplication.run(EureakServerApplication.class);}
}

启动以后打开网页检查。
请添加图片描述


3.2、启动Client

3.2.1、dependency

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.3.7.RELEASE</version><type>pom</type><scope>import</scope>
</dependency>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Hoxton.SR12</version><type>pom</type><scope>import</scope>
</dependency>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

3.2.2、配置文件

# 节点在server中注册的名字
spring:application:name: msb-order
server:port: 9002eureka:client:# 这个一定要配对,server地址后面默认要加一个上下文eurekaservice-url:defaultZone: http://localhost:8761/eurekamanagement:endpoints:web:exposure:include: shutdown #暴露shutdown端点endpoint:shutdown:enabled: true #再次确认暴露shutdown端点feign:tokenId: 11111111111111111111

3.3.3、Client端启动代码

注意有两个注解可以将其标注为Client,分别是@EnableDiscoveryClient@EnableEurekaClient

这里推荐使用@EnableDiscoveryClient,因为后者是netfliex提供的,如果使用后者,后期要更换其它注册中心就需要更换注解,比较麻烦。

@EnableDiscoveryClient // 这是官方提供的  ,我们以后可能切换其他的注册中心比如说nacos,那我们就直接切换就行了
//@EnableEurekaClient  // 是netflix提供的,如果用这个注解就只能服务于eureka
@SpringBootApplication
public class MsbOrderApplication {public static void main(String[] args) {SpringApplication.run(MsbOrderApplication.class);}
}

同样的配置和代码,再启动一个叫msb-stock的服务

到Server的页面查看,两个服务都注册成功。

请添加图片描述

3.3、服务之间获取信息

引入LoadBalancerClient,从这个bean中可以获得其他注册的client元数据,比如地址,端口号等。

下面这个例子展示了如何获取其他client的元信息并且调用其它client的服务。

@Service
public class OrderService {@Autowiredprivate LoadBalancerClient eurekaClient;@Autowiredprivate RestTemplate restTemplate;public void getUser() {ServiceInstance instance = eurekaClient.choose("msb-user");String hostname = instance.getHost();int port = instance.getPort();String uri = "/getUserInfo?userId=" + userId;String url = "http://" + hostname + ":" + port + uri;return restTemplate.getForObject(url, String.class);}}
http://www.dt0577.cn/news/27716.html

相关文章:

  • 网站广告尺寸友链交易平台
  • 网站推广策划方式十大基本营销方式
  • 设计公司网站套餐微信朋友圈广告如何投放
  • 网页设计ppt模板深圳谷歌优化seo
  • 响应式网站建设公司武汉竞价托管公司
  • 做外贸的网站看啥书高德北斗导航
  • 网站的增加条件设计百度推广竞价排名
  • 聊城网站制作公司电话seo 知乎
  • 网站开发实训要求苏州百度快速排名优化
  • 建网站需要多少钱网店运营与管理
  • 足球网站怎么做的世界新闻最新消息
  • 公司怎么注册官方网站新开传奇网站发布站
  • 嘉兴做美食图片的网站优质的seo网站排名优化软件
  • 陕西手机网站建设公司哪家好江苏企业seo推广
  • 网站标头图片切换什么推广平台好
  • 网络营销名词解释电子商务漯河seo推广
  • 专项培训网站建设方案seo网址优化靠谱
  • 金蝶软件公司简介西安seo外包公司
  • ps网站专题怎么做搜索引擎优化是什么意思啊
  • 有没有专门做中式的设计网站app软件开发
  • 自己做的表白网站大连网络推广公司哪家好
  • 移动端网站是什么网站备案查询系统
  • 江西网站开发公司宽带推广方案
  • 微信小程序投放惠州seo排名公司
  • 网站不备案备案国内新闻最新消息今天
  • 做新闻网站灰色词排名上首页
  • 哪些网站是java开发的alexa
  • 免费网站app软件餐饮营销方案
  • 刚做网站和搜出来的不一样建设网站的基本流程
  • 网站建设成本计划百度竞价开户需要多少钱