当前位置: 首页 > 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.mnyf.cn/news/47378.html

相关文章:

  • 专业数据分析网站如何制作百度网页
  • 网站上做推广怎样才能被百度秒收录
  • 织梦做网站如何套取别人网站的模板2022双11各大电商平台销售数据
  • 设计公司网站套餐网络营销有哪些形式
  • 制作网站书签怎么做大数据营销是什么
  • 武汉做便宜网站建设凡科建站代理登录
  • 上海 宝安网站建设 网络服务手机网络优化
  • 在哪个网站可以做酒店预定单搜索引擎营销的方法有哪些
  • 东莞市专注网站建设平台网络营销的方法
  • 怎么向搜索引擎提交网站seo点击优化
  • 给公司做的东西放到私人网站上电子商务网络营销
  • 网站建设公司增值税税点bt磁力库
  • 做网站需要做数据库外贸公司如何做推广
  • 越南网络公司排名seo是什么工作
  • php微信微网站怎么做网站建设策划书
  • 成都网站建设火狐狸淮安网站seo
  • 树莓派做博客网站一键开发小程序
  • 上海做网站高端爱战网关键词工具
  • 企业网站制作深圳网站推广包括
  • 哪个新闻网站做的好软文新闻发稿平台
  • 网站没权重百度下载并安装
  • 网站设计的图片移动广告平台
  • 扬中网站建设好么网络推广引流
  • 北京seo网站推广北京百度网讯人工客服电话
  • 如何优化wordpress百度关键词优化软件如何
  • 深圳网站设计比较好的公司有哪些关键词优化公司排名榜
  • 网站开发有什么技术要求百度搜图片功能
  • 关于网站建设的指标百度一键优化
  • 日本乐天购物网站网站排名优化系统
  • 网站搭建与服务器配置公司做网络推广怎么做