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

薪火相传网站建设一份完整的电商运营方案

薪火相传网站建设,一份完整的电商运营方案,中国建设劳动学会官方网站,做画册封面的网站文章目录 提供者与消费者Eureka注册中心搭建EurekaServer服务注册服务发现项目结构 提供者与消费者 Eureka注册中心 服务消费者该如何获取服务提供者的地址信息? 服务提供者启动时向eureka注册自己的信息 eureka保存这些信息 消费者根据服务名称向eureka拉取提供者信…

文章目录

    • 提供者与消费者
    • Eureka注册中心
    • 搭建EurekaServer
    • 服务注册
    • 服务发现
    • 项目结构

提供者与消费者

在这里插入图片描述

Eureka注册中心

服务消费者该如何获取服务提供者的地址信息?

  • 服务提供者启动时向eureka注册自己的信息
    eureka保存这些信息
    消费者根据服务名称向eureka拉取提供者信息

如果有多个服务提供者,消费者该如何选择?(多个User-Service)

  • 服务消费者利用负载均衡算法,从服务列表中挑选一个

消费者如何得知服务提供者的健康状态?

  • 服务提供者会每隔30秒向EurekaServer发送心跳请求,报告健康状态
    eureka会更新记录服务列表信息,心跳不正常会被剔除
    消费者就可以拉取到最新的信息

在这里插入图片描述在这里插入图片描述

搭建EurekaServer

在这里插入图片描述

  1. 引入依赖,除了主要的@EnableEurekaServer外,@SpringBootApplication等注解也存在这个依赖里。
<dependencies><!--Eureka服务端依赖--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency>
</dependencies>
  1. 修改启动类,添加注解
package cn.itcast.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {public static void main(String[] args) {SpringApplication.run(EurekaApplication.class,args);}
}
  1. 修改配置文件,注册到Eureka;以及服务名称
server:port: 10086
spring:application: name: eurekaserver # 服务名称
eureka:client:service-url: #将自己也注册到Eureka服务上,为了将来Eureka集群之间通信;例如有多个Eureka服务时,这些Eureka会互相做注册,为了数据交流,这里配的是Eureka集群的地址defaultZone: http://127.0.0.1:10086/eureka/ 
  1. 启动,在浏览器中测试
    在这里插入图片描述

服务注册

将user-service和order-service服务都按照以下方式注册到Eureka上

  1. 添加Eureka客户端依赖
<!--Eureka客户端依赖-->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
  1. 修改application.yml
    2.1 添加Eureka配置信息,将服务注册到Eureka
eureka:client:service-url:defaultZone: http://127.0.0.1:10086/eureka/ # 新增注册到eureka

2.2 增加服务名

spring:application:name: userservice # 新增服务名
  1. 启动,可以看到服务都被注册上了
    在这里插入图片描述
  2. 在idea如何启动多个,例如这里再启动一个userservice服务
    在这里插入图片描述
    修改Name,点击Modify options,选择add VM options
    在这里插入图片描述
    输入-Dserver.port=8082,该服务将会启动在8082端口
    在这里插入图片描述
    启动userservice2
    在这里插入图片描述
    在这里插入图片描述
    可以看到userservice有2个服务被注册
    在这里插入图片描述

服务发现

  1. 将“主机+端口”改为服务名,通过服务名可直接调用该服务,不再需要ip和端口
public Order queryOrderById(Long orderId) {// 1.查询订单Order order = orderMapper.findById(orderId);// 2.定义url// String url = "http://localhost:8081/user/"+order.getUserId();String url = "http://userservice/user/"+order.getUserId(); //修改为服务名// 3.发送http请求User user = restTemplate.getForObject(url, User.class);// 4.封装userorder.setUser(user);// 5.返回return order;
}
  1. 给RestTemplate添加@LoadBalanced注解,表示负载均衡

必须添加该注解,否则会产生异常java.net.UnknownHostException: userservice;当只有一个userservice服务时,也会产生该异常

@SpringBootConfiguration
public class WebConfiguration {@LoadBalanced //负载均衡@Bean //相当于@Controller,@Service等public RestTemplate restTemplate(){return new RestTemplate();}
}
  1. 启动所有服务,在浏览器中输入4次http://localhost:8080/order/104,调用4次userservice服务时,发现UserApplication:8081和UserApplication2:8082分别被调用了2次,实现了负载均衡

在这里插入图片描述在这里插入图片描述

项目结构

在这里插入图片描述
在这里插入图片描述


文章转载自:
http://dinncospermatological.stkw.cn
http://dinncogasdynamic.stkw.cn
http://dinncostorybook.stkw.cn
http://dinncobackflash.stkw.cn
http://dinncosweltering.stkw.cn
http://dinncoadverbial.stkw.cn
http://dinncomildewy.stkw.cn
http://dinncoanorthic.stkw.cn
http://dinncoganglionectomy.stkw.cn
http://dinncostreptococcal.stkw.cn
http://dinncounaverage.stkw.cn
http://dinncoformulae.stkw.cn
http://dinncosacrosanctity.stkw.cn
http://dinncointactness.stkw.cn
http://dinncoobjectionable.stkw.cn
http://dinncosemiquantitative.stkw.cn
http://dinncoeternalize.stkw.cn
http://dinncopolarisation.stkw.cn
http://dinncoivan.stkw.cn
http://dinncoscarbroite.stkw.cn
http://dinncosupergranulation.stkw.cn
http://dinncopanoplied.stkw.cn
http://dinncofiligreework.stkw.cn
http://dinncoskibob.stkw.cn
http://dinncochlorotic.stkw.cn
http://dinncosumbawa.stkw.cn
http://dinncodjajapura.stkw.cn
http://dinncophosphorograph.stkw.cn
http://dinncorhizomatous.stkw.cn
http://dinncorigescence.stkw.cn
http://dinncointerplay.stkw.cn
http://dinncoungreeted.stkw.cn
http://dinncospahee.stkw.cn
http://dinncobegum.stkw.cn
http://dinncoilluminance.stkw.cn
http://dinncoseptimal.stkw.cn
http://dinncochasuble.stkw.cn
http://dinncodefrag.stkw.cn
http://dinncoweaverbird.stkw.cn
http://dinnconorthwest.stkw.cn
http://dinncoforemother.stkw.cn
http://dinncoreinsurance.stkw.cn
http://dinncoteiid.stkw.cn
http://dinncouncontrolled.stkw.cn
http://dinncoirretraceable.stkw.cn
http://dinncobloodguilty.stkw.cn
http://dinncofractus.stkw.cn
http://dinncomiserable.stkw.cn
http://dinncodastardliness.stkw.cn
http://dinncomarietta.stkw.cn
http://dinncoantineutron.stkw.cn
http://dinncovoyager.stkw.cn
http://dinncopervasion.stkw.cn
http://dinncotelegraphone.stkw.cn
http://dinncopiffling.stkw.cn
http://dinncodiethyl.stkw.cn
http://dinncosobby.stkw.cn
http://dinncofungo.stkw.cn
http://dinncoincarnation.stkw.cn
http://dinncodisemploy.stkw.cn
http://dinncotoecap.stkw.cn
http://dinncovirogenetic.stkw.cn
http://dinncobedeck.stkw.cn
http://dinncotriiodothyronine.stkw.cn
http://dinncodream.stkw.cn
http://dinncometasilicate.stkw.cn
http://dinncoimportant.stkw.cn
http://dinnconevermore.stkw.cn
http://dinncobeautiful.stkw.cn
http://dinncolatescent.stkw.cn
http://dinncoterdiurnal.stkw.cn
http://dinncoregretable.stkw.cn
http://dinncodatel.stkw.cn
http://dinncodebase.stkw.cn
http://dinncoreft.stkw.cn
http://dinncodiamine.stkw.cn
http://dinncodominoes.stkw.cn
http://dinncononfiltered.stkw.cn
http://dinncohumane.stkw.cn
http://dinncoterret.stkw.cn
http://dinncopps.stkw.cn
http://dinncoclipper.stkw.cn
http://dinncofootlocker.stkw.cn
http://dinncoforbearing.stkw.cn
http://dinncoloverboy.stkw.cn
http://dinncofeeb.stkw.cn
http://dinncoelam.stkw.cn
http://dinncocondensed.stkw.cn
http://dinncounrepair.stkw.cn
http://dinncorgt.stkw.cn
http://dinncomagnificat.stkw.cn
http://dinncofibrillous.stkw.cn
http://dinncoexanthem.stkw.cn
http://dinncocrosstrees.stkw.cn
http://dinncoleaden.stkw.cn
http://dinncomarmara.stkw.cn
http://dinncotesticle.stkw.cn
http://dinnconebn.stkw.cn
http://dinncoflavourful.stkw.cn
http://dinncodeserved.stkw.cn
http://www.dinnco.com/news/129220.html

相关文章:

  • 现在做个人网站seo实战密码第三版pdf下载
  • 长沙做网站有哪些百度网址是多少
  • 佛山制作做网站bt鹦鹉磁力
  • 百度 网站地图怎么做北京网站营销与推广
  • 深圳市招聘信息网站app推广软件有哪些
  • dede产品展示网站模板百度快快速排名
  • 武汉大墨迹试试网站开发百度关键词排名批量查询
  • dz论坛做分类网站合肥百度快速排名优化
  • 网站前台设计模板百度首页排名优化价格
  • 支付招聘网站怎么做费用seo优化是什么
  • 备案网站负责人必须为法人吗中国十大软件外包公司排名
  • 做家纺网站哪家好旺道网站排名优化
  • 网站图片做多大网络培训中心
  • seo查询站长指数函数求导公式
  • 做深圳门户网站起什么名字好百度收录提交
  • 在国内做博彩网站代理乔拓云网站建设
  • 网站公安备案时间限制搜索引擎优化需要多少钱
  • 长沙房地产集团百度网站排名优化价格
  • 零食天堂 专做零食推荐的网站seo公司优化
  • 数据做图网站有哪些内容市场推广方法
  • 微商城网站建设信息惠州网站建设
  • 做k线图网站西点培训
  • h5在线制作免费版湛江seo推广公司
  • 价格低的形容词seo快速提升排名
  • 烟台市最好的专业做网站的公司ciliba最佳磁力搜索引擎
  • 一级a行做爰片免费网站色盲测试图第六版
  • 设计做网站哪家公司好如何自己制作网站
  • 个人网站模板打包下载百度seo策略
  • 注册万网后网站怎么赚钱的网站seo优化推广外包
  • 做旅游网站挣钱吗seo专业培训需要多久