成都网站建设设计

将想法与焦点和您一起共享

uri:lb://怎么在springcloudgateway中使用-创新互联

uri: lb://怎么在spring cloud gateway中使用?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

我们提供的服务有:成都做网站、网站建设、微信公众号开发、网站优化、网站认证、石泉ssl等。为近1000家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的石泉网站制作公司

在gateway中配置uri配置有三种方式,包括
第一种:ws(websocket)方式: uri: ws://localhost:9000
第二种:http方式: uri: http://localhost:8130/
第三种:lb(注册中心中服务名字)方式: uri: lb://brilliance-consumer

uri: lb://怎么在spring cloud gateway中使用

其中ws和http方式不容易出错,因为http格式比较固定,但是lb方式比较灵活自由。不考虑网关,只考虑服务时,服务名命名时比较自由,都能启动被访问,被注册到注册中心,但是如果提供给gateway使用时,就会对服务命名方式有特殊要求了。
能被gateway的lb方式识别到的命名规则为:

"[a-zA-Z]([a-zA-Z]|\\d|\\+|\\.|-)*:.*"

这也意味着,java命名规范中可以使用的英文下划线("_")不能被识别,而我命名为:brilliance_consumer,刚好带下划线,改为brilliance-consumer后则可以正常通过网关访问自己项目。
如果名字中有非*“a-zA-Z:.”*规则字符,则会报错,
规则见包org.springframework.cloud.gateway.filter中的类RouteToRequestUrlFilter:

uri: lb://怎么在spring cloud gateway中使用uri: lb://怎么在spring cloud gateway中使用

报异常信息为:

  java.lang.IllegalStateException: Invalid host: lb://brilliance_consumer
 at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:86) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
 Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
 |_ checkpoint ⇢ org.springframework.web.cors.reactive.CorsWebFilter [DefaultWebFilterChain]
 |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
 |_ checkpoint ⇢ HTTP GET "/api/product/productDetail" [ExceptionHandlingWebHandler]
Stack trace:
  at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:86) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  at org.springframework.cloud.gateway.handler.FilteringWebHandler$GatewayFilterAdapter.filter(FilteringWebHandler.java:138) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$filter$0(FilteringWebHandler.java:118) ~[spring-cloud-gateway-server-2.2.6.RELEASE.jar:2.2.6.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Mono.subscribe(Mono.java:4252) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Mono.subscribe(Mono.java:4252) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:150) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:274) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:851) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onNext(FluxSwitchIfEmpty.java:67) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1782) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:144) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxMap$MapSubscriber.onNext(FluxMap.java:114) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoNext$NextSubscriber.onNext(MonoNext.java:76) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:274) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:851) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onNext(FluxOnErrorResume.java:73) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoPeekTerminal$MonoTerminalPeekSubscriber.onNext(MonoPeekTerminal.java:173) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1782) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoFilterWhen$MonoFilterWhenMain.onNext(MonoFilterWhen.java:140) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2344) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoFilterWhen$MonoFilterWhenMain.onSubscribe(MonoFilterWhen.java:103) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoJust.subscribe(MonoJust.java:54) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Mono.subscribe(Mono.java:4252) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:441) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onNext(FluxConcatMap.java:243) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:91) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onNext(FluxDematerialize.java:38) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:267) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:225) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.request(FluxDematerialize.java:120) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:228) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxDematerialize$DematerializeSubscriber.onSubscribe(FluxDematerialize.java:70) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Mono.subscribe(Mono.java:4252) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.drain(FluxConcatMap.java:441) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.onSubscribe(FluxConcatMap.java:211) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:161) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:86) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:52) [reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.Mono.subscribe(Mono.java:4252) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.drain(MonoIgnoreThen.java:172) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:56) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.3.12.RELEASE.jar:3.3.12.RELEASE]
  at reactor.netty.http.server.HttpServerHandle.onStateChange(HttpServerHandle.java:65) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:518) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at reactor.netty.tcp.TcpServerBind$ChildObserver.onStateChange(TcpServerBind.java:278) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:475) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:96) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:191) ~[reactor-netty-0.9.15.RELEASE.jar:0.9.15.RELEASE]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324) ~[netty-codec-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296) ~[netty-codec-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
  at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_221]

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联网站建设公司,的支持。


当前题目:uri:lb://怎么在springcloudgateway中使用-创新互联
新闻来源:http://chengdu.cdxwcx.cn/article/didihd.html