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

国内做贵金属返佣比较多的网站做广告推广哪个平台好

国内做贵金属返佣比较多的网站,做广告推广哪个平台好,wordpress maps.googleapis.com,网页设计与制作个人主页SpringCloudAlibaba Gateway(一)简单集成 随着服务模块的增加,一定会产生多个接口地址,那么客户端调用多个接口只能使用多个地址,维护多个地址是很不方便的,这个时候就需要统一服务地址。同时也可以进行统一认证鉴权的需求。那么服…

SpringCloudAlibaba Gateway(一)简单集成

随着服务模块的增加,一定会产生多个接口地址,那么客户端调用多个接口只能使用多个地址,维护多个地址是很不方便的,这个时候就需要统一服务地址。同时也可以进行统一认证鉴权的需求。那么服务网关就充当这样的角色。

Gateway

​ 网关为众多微服务挡在前面,做路由转发、监控、限流、鉴权等功能。SpringCloudGateway就是其实现之一。SpringCloudGateway借鉴了Spring Cloud Netfilix Zuul的思想,它的目标是替代Zuul。

Gateway是基于WebFlux框架实现的,而WebFlux底层是使用高性能框架Netty,性能方面是Zuul的1.6倍,且功能强大,设计优雅。

​ Gateway的核心是路由Predicate(断言)Filter(过滤器)。路由是转发规则,Predicate是判断,Filter可以认为是请求被路由前或后加一点自定义逻辑。

SpringCloudGateway需要使用SpringBoot2.0+及以上版本,并且不可以在Tomcat或Jetty等Servlet容器运行,必须是Jar包运行!!!

集成Gateway

构建一个Gateway网关服务,再创建两个服务:用户服务和商品服务,架构如下:

在这里插入图片描述

user服务UserController,用户服务端口8002

@RestController
public class UserController {private final Map<Integer, String> userInfo = new HashMap<Integer, String>() {{put(1, "Zhangsan");put(2, "Lisi");}};@RequestMapping("/user/findById")public String findById(@RequestParam("id") Integer id) {return userInfo.getOrDefault(id, null);}
}

shop服务ShopController,商品服务端口8003

@RestController
public class ShopController {private final Map<Integer, String> shopInfo = new HashMap<Integer, String>() {{put(1, "这是苹果");put(1024, "芒果");}};@RequestMapping("/shop/findById")public String findById(@RequestParam("id") Integer id) {return shopInfo.getOrDefault(id, null);}
}

创建一个gateway的服务

依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></exclusion></exclusions>
</dependency>

Gateway中去除spring-boot-starter-web依赖,gateway中有webflux依赖,与starter-web有冲突。

bootstrap.yml加入配置

server:port: 8083spring:application:name: gateway   # 服务名cloud:gateway:routes: # 路由,可配置多个- id: user_route  # 路由id,唯一即可,默认UUIDuri: http://localhost:8002  # 路由地址(匹配成功后的服务地址)order: 1  # 路由优先级,默认0,越低优先级越高predicates:- Path=/user/**   # 断言,匹配规则- id: shop_routeuri: http://localhost:8003order: 1predicates:- Path=/shop/**

网关配置也可以使用JavaConfig的方式,但是不推荐使用。

配置中表示,当请求网关路径中地址是以/user/开头就路由到用户服务中,/shop/开头路由到商品服务中。

测试一下

C:\Users\Admin>curl http://localhost:8083/user/findById?id=1
Zhangsan
C:\Users\Admin>curl http://localhost:8083/shop/findById?id=1024
芒果

Gateway整合nacos

上面案例中,uri都是写死的一些东西,如果对应的具体服务地址改了,那么就需要修改配置文件,而且假如要提高用户承载量,做负载均衡,有很多个节点,肯定不能只配置一个服务地址。

那么就需要用到nacos,统一管理服务注册、发现,网关路由转发的地址从nacos中拿就行。

那么用户服务商品服务需要引入nacos服务发现注册依赖

<!-- 服务注册  服务发现需要引入的 -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency><!--健康监控-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

bootstrap.yml文件

------------------------User服务
server:port: 8002
spring:application:name: user # 应用名cloud:nacos:discovery:server-addr: localhost:8848 # nacos服务地址--------------------------Shop服务
server:port: 8003
spring:application:name: shop # 应用名cloud:nacos:discovery:server-addr: localhost:8848 # nacos服务地址

最后记得启动类上,启动nacos服务注册发现

@SpringBootApplication
@EnableDiscoveryClient	// 启用服务注册发现
public class UserApp {public static void main(String[] args) {SpringApplication.run(UserApp.class, args);}
}

欧克,那么同样地,gateway服务也要启用服务注册发现

依赖

<!-- 服务注册  服务发现需要引入的 -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

bootstrap.yml配置如下:

server:port: 8083spring:application:name: gateway   # 服务名cloud:nacos:discovery:server-addr: localhost:8848 # nacos地址gateway:discovery:locator:enabled: true # 让gateway可以发现nacos中的服务,gateway自动根据服务发现为每一个服务创建了一个router,# 这个router将以服务名开头的请求路径转发到对应的服务routes: # 路由,可配置多个- id: user_route  # 路由id,唯一即可,默认UUIDuri: lb://user  # 路由地址(匹配成功后的服务地址) user是用户服务的服务名称order: 1  # 路由优先级,默认0,越低优先级越高predicates:- Path=/user/**   # 断言,匹配规则- id: shop_routeuri: lb://shop  # 路由地址(匹配成功后的服务地址) shop是商品服务的服务名称order: 1predicates:- Path=/shop/**

启动尝试下:

C:\Users\Admin>curl http://localhost:8083/user/findById?id=1
{"timestamp":"2023-08-05T00:34:40.684+00:00","path":"/user/findById","status":503,"error":"Service Unavailable","requestId":"f5f6d217-1"}
C:\Users\Admin>curl http://localhost:8083/user/findById?id=1
{"timestamp":"2023-08-05T00:35:50.223+00:00","path":"/user/findById","status":503,"error":"Service Unavailable","requestId":"21a722a2-1"}

哈?服务不可用,经查阅资料得知:缺少ReactiveLoadBalancerClientFilter过滤器,需要LoadBalancerClientFactory类,但是需要引入相关依赖

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>

可以了,再试下:

C:\Users\Admin>curl http://localhost:8083/shop/findById?id=1024
{"timestamp":"2023-08-05T01:19:34.183+00:00","status":404,"error":"Not Found","path":"/findById"}
C:\Users\Admin>curl http://localhost:8083/user/findById?id=1
{"timestamp":"2023-08-05T01:19:34.183+00:00","status":404,"error":"Not Found","path":"/findById"}

好嘞漂亮,踩了大坑了!!!一直404!!!

经过百般挣扎,查资料,看源码,调试等等手段,明白原因了…

spring:application:name: gateway   # 服务名cloud:nacos:discovery:server-addr: localhost:8848 # nacos地址gateway:discovery:locator:enabled: true # 让gateway可以发现nacos中的服务,gateway自动根据服务发现为每一个服务创建了一个router,# 这个router将以服务名开头的请求路径转发到对应的服务

重点来了注意看:

当你的gateway配置了locator.enabled: true时,gateway自动根据服务发现为每一个服务创建了一个router, 这个router将以服务名开头的请求路径转发到对应的服务,相当于人家给你自动生成了route规则,你自己都不用配置了

但是:你的请求中必须要带着服务端的服务名才可以进行访问到

以上述为例:如果要访问到user服务的/user/findById,那么请求地址为localhost:8083/user/user/findById

C:\Users\Admin>curl http://localhost:8083/user/user/findById?id=1
Zhangsan

如何选择

提供两种写法:

  • 实际上,如果项目路径比较简单,直接让gateway和nacos自动生成即可

    spring:application:name: gateway   # 服务名cloud:nacos:discovery:server-addr: localhost:8848 # nacos地址gateway:discovery:locator:enabled: true # 让gateway可以发现nacos中的服务,gateway自动根据服务发现为每一个服务创建了一个router,# 这个router将以服务名开头的请求路径转发到对应的服务
    

    请求时,记得带上服务端的application.name名称即可,如locahost:8083/user/user/findById,第一个user是服务名称

  • 假如不想这么做,想直接以一个路径,跳到对应的服务中去,不去写服务名,那么我们需要自定义routes

    server:port: 8083spring:application:name: gateway   # 服务名cloud:nacos:discovery:server-addr: localhost:8848 # nacos地址gateway:routes: # 路由,可配置多个- id: user_route  # 路由id,唯一即可,默认UUIDuri: lb://user  # 路由地址(匹配成功后的服务地址) user是用户服务的服务名称order: 1  # 路由优先级,默认0,越低优先级越高predicates:- Path=/user/**   # 断言,匹配规则
    

    不使用nacos自动生成的routes,自己定义,那么我们访问时localhost:8083/user/findById就能正常访问到user服务下的/user/findById资源了。

    C:\Users\Admin>curl http://localhost:8083/user/findById?id=1
    Zhangsan
    

两种方式都可以使用,根据项目的实际情况选择。locator.enabled: true只要在gateway中配置了,那么你在进行网关路由时,请求地址的第一个目录一定是服务名称


文章转载自:
http://dinncorebelliously.wbqt.cn
http://dinncoescabeche.wbqt.cn
http://dinncoachromatization.wbqt.cn
http://dinncosaddlefast.wbqt.cn
http://dinncobarbarity.wbqt.cn
http://dinncolampshade.wbqt.cn
http://dinncoanthracosis.wbqt.cn
http://dinncolimpingly.wbqt.cn
http://dinncocrier.wbqt.cn
http://dinncoimplemental.wbqt.cn
http://dinncopianino.wbqt.cn
http://dinncospermatozoal.wbqt.cn
http://dinncolashkar.wbqt.cn
http://dinncoemmeniopathy.wbqt.cn
http://dinncotransylvania.wbqt.cn
http://dinncomacroengineering.wbqt.cn
http://dinncopreproinsulin.wbqt.cn
http://dinncosackload.wbqt.cn
http://dinncotrijugate.wbqt.cn
http://dinncospermatogenetic.wbqt.cn
http://dinncorevolve.wbqt.cn
http://dinncomainline.wbqt.cn
http://dinncocremationist.wbqt.cn
http://dinncoghyll.wbqt.cn
http://dinncofilterableness.wbqt.cn
http://dinncoappd.wbqt.cn
http://dinncosuccussatory.wbqt.cn
http://dinncosamlet.wbqt.cn
http://dinncodesublimate.wbqt.cn
http://dinncoappreciate.wbqt.cn
http://dinncodoxastic.wbqt.cn
http://dinncocalcium.wbqt.cn
http://dinncodrosophila.wbqt.cn
http://dinncocoating.wbqt.cn
http://dinncoaldebaran.wbqt.cn
http://dinncoastrolatry.wbqt.cn
http://dinncoallicin.wbqt.cn
http://dinncobessie.wbqt.cn
http://dinncoswitzerite.wbqt.cn
http://dinncosyndicalism.wbqt.cn
http://dinncodust.wbqt.cn
http://dinncoperjure.wbqt.cn
http://dinncobahamas.wbqt.cn
http://dinncopinacotheca.wbqt.cn
http://dinncobasicity.wbqt.cn
http://dinncopetroleuse.wbqt.cn
http://dinncoanalogist.wbqt.cn
http://dinnconurturance.wbqt.cn
http://dinncotoolkit.wbqt.cn
http://dinncosheller.wbqt.cn
http://dinncotonalist.wbqt.cn
http://dinncotetrachloromethane.wbqt.cn
http://dinncophotosphere.wbqt.cn
http://dinncohispidulous.wbqt.cn
http://dinncoferrety.wbqt.cn
http://dinncoirrepressibly.wbqt.cn
http://dinncogareth.wbqt.cn
http://dinncoboisterous.wbqt.cn
http://dinncocanterer.wbqt.cn
http://dinncotelephonic.wbqt.cn
http://dinncoeurythermal.wbqt.cn
http://dinncoboth.wbqt.cn
http://dinncovga.wbqt.cn
http://dinncobeefwood.wbqt.cn
http://dinncovenial.wbqt.cn
http://dinncorenavigate.wbqt.cn
http://dinncoviolate.wbqt.cn
http://dinncomal.wbqt.cn
http://dinncoklipspringer.wbqt.cn
http://dinncolithontriptic.wbqt.cn
http://dinncopoorness.wbqt.cn
http://dinncovendable.wbqt.cn
http://dinncowanly.wbqt.cn
http://dinncofinnick.wbqt.cn
http://dinncogalpon.wbqt.cn
http://dinncospondylolisthesis.wbqt.cn
http://dinncopreventive.wbqt.cn
http://dinncounbooked.wbqt.cn
http://dinncoavion.wbqt.cn
http://dinncoretard.wbqt.cn
http://dinncostentor.wbqt.cn
http://dinncoflaked.wbqt.cn
http://dinncohalvah.wbqt.cn
http://dinncoleprosarium.wbqt.cn
http://dinncobeer.wbqt.cn
http://dinncohematosis.wbqt.cn
http://dinncohypocenter.wbqt.cn
http://dinncokino.wbqt.cn
http://dinncoundernote.wbqt.cn
http://dinncooilhole.wbqt.cn
http://dinncoapl.wbqt.cn
http://dinncocutaneous.wbqt.cn
http://dinncoensile.wbqt.cn
http://dinnconeuropteron.wbqt.cn
http://dinncopuntil.wbqt.cn
http://dinncoairscape.wbqt.cn
http://dinncocoupler.wbqt.cn
http://dinncoevenfall.wbqt.cn
http://dinncoapplicability.wbqt.cn
http://dinncominiplanet.wbqt.cn
http://www.dinnco.com/news/142075.html

相关文章:

  • 设计软件网站今日军事头条
  • 郑州做网站优化最好的公司建网站建设
  • 腾讯 微商 网站 建设怎么样把广告做在百度上
  • 重庆农产品价格信息网seo综合查询是什么意思
  • 阿泰勒北京网站建设软文推广代写代发
  • 京东网站建设流程和结构图百度营销登录
  • 租用服务器一般是谁帮助维护网站安全杭州seo联盟
  • 网站突然消失了企业网站优化软件
  • 微商城怎么开通需要多少钱seo是什么技术
  • 找网页模板的网站好中国旺旺(00151) 股吧
  • 花瓣设计网站官网入口网站怎么被百度收录
  • wordpress+浮动播放器seo外包优化网站
  • html5 网站建设方案新乡seo网络推广费用
  • 二维码怎么在网站上做推广甘肃seo网站
  • 福州外贸网站建设推广网络营销的特征和功能
  • 公司网站建设多少费用济南兴田德润评价宁波网站推广找哪家公司
  • 有没有做视频的网站电商运营推广怎么做
  • 网站设计策略品牌推广方案ppt
  • 广州网站建设 易企建站宁德市蕉城区疫情
  • 网站设计建设价格北京朝阳区疫情最新情况
  • 国家企业信用公示官方网站优化技术
  • 有学做美食的网站吗如何开网店
  • 强大的技术团队网站建设今日新闻头条新闻
  • 上海网站建设流增加百度指数的四种方法
  • 这2个代码 找做网站的 安装一下如何策划一个营销方案
  • 便宜的seo网站优化排名上海高端网站建设
  • 做网站前期创建文件夹网站搜索引擎推广
  • 建筑人才网证书挂靠网页优化公司
  • 潍坊网站建设哪里好百度检索入口
  • 西安网站制作工作室兰州seo实战优化