我很困惑何时使用spring cloud config server和consul。两者都会以自己的方式读取配置文件。你能告诉我什么时候使用spring cloud 配置服务器以及什么时候使用consul吗?
我正在尝试将 Spring Cloud Gateway 与 Spring Security 结合使用。但不幸的是,看起来安全性并不重要,所有请求都经过其目的地,或者至少尝试经过。只是尝试一下,因为我每次都会收到 HTTP 状态 503。我在 Spring 5,并尝试尽可能地“反应”。我究竟做错了什么?当服务尝试使用功能区负载平衡查找目的地时,日志中没有任何有趣的内容,只有常见的行。我还启用了网关服务器上的访问日志,希望能得到一些额外的信息,但什么也没有。
我已经简化了我的代码,这是不起作用的最小配置。
POM依赖和依赖管理:
<dependencies>
<!-- Spring Cloud Gateway service -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<!-- Spring Cloud Eureka client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- Spring Cloud config client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml:
spring:
application:
name: …Run Code Online (Sandbox Code Playgroud) 我们正在使用RouteDefinitionLocator. 我们有两个服务应该在同一路由路径上注册,如果另一个服务不存在,其中一个服务将作为后备服务。具体路径的首选路线为:
RouteDefinition{id='CompositeDiscoveryClient_ms-1400133464', predicates=[PredicateDefinition{name='Path', args={pattern=/yambas/rest/apps/*/models/ms/**}}], filters=[FilterDefinition{name='RewritePath', args={regexp=/yambas/rest/apps/(?<remaining>.*), replacement=/ms/apps/${remaining}}}], uri=lb://ms, order=0}
Run Code Online (Sandbox Code Playgroud)
还有更一般的一个,只有在找到其他路线时才会触发:
RouteDefinition{id='CompositeDiscoveryClient_yambas-1171178634', predicates=[PredicateDefinition{name='Path', args={pattern=/yambas/rest/**}}], filters=[], uri=lb://yambas, order=0}
Run Code Online (Sandbox Code Playgroud)
因此,当调用 时/yambas/rest/apps/bla/models/ms,应使用第一个路由,而当调用 时/yambas/rest/apps/bla/models/otherms/*,应使用第二个路由(后备)。
问题是,即使是路线上的顺序属性似乎也无法解决这个问题;目前我们发现无法设置此路线的顺序/优先级。这是有意的吗?
我是 spring-cloud-gateway 的新手,如果我按预期方式解决了我的问题,我无法回答这个问题。我希望有人能给我指出正确的方向,提供建议或提供一些示例性示例代码。
要求:我的 spring-cloud-gateway 服务的传入请求应转发到正确的后端服务(有 X 个这样的后端服务,每个后端服务负责特定任务)。请求本身不包含足够的信息来决定路由到哪个后端服务。
存在附加的 REST 服务,可将任意 URL 映射到负责后端服务名称。响应格式是一些小的 JSON,包含要转发到的后端服务的名称。
使用 spring-cloud-gateway 实现此功能的最简单/最佳/最智能/预期的解决方案是什么?
我尝试实现一个GatewayFilter首先调用映射服务并取决于GATEWAY_REQUEST_URL_ATTR交换结果集的方法。这工作正常。但我还有其他问题。
.uri("not://needed"))路线设置中的部分 可以省略吗?
为什么订单金额需要高于9999?(参见代码示例)
@SpringBootApplication
@RestController
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes().route(r -> r
.alwaysTrue()
.filters(f -> f.filter(new CustomRequestFilter()))
.uri("not://needed")) // how to omit ?
.build();
}
public static class CustomRequestFilter implements GatewayFilter, Ordered {
@Override
public int getOrder() {
return 10000; // …Run Code Online (Sandbox Code Playgroud) 我有 Spring Cloud 项目,每个微服务我认为我有很多包。我还有包含实体和自定义请求响应对象的模型包。
问题1:实体类包名必须是什么?实体还是模型?
问题2:Searchrequest&Searchresponse等请求响应类必须保存在哪里?在模型包中或者我必须创建其他包?
问题 3:是否存在一些包结构标准?(请给我链接)
我们一直在评估 Spring-Stomp-Broker-websockets,以使其成为在 AWS 上运行的全双工类型消息应用程序。我们原本希望使用 Amazon MQ。我们向个人用户推送消息,也进行广播。所以从功能上来说,这个堆栈看起来确实不错。我们有大约 40,000 - 80,000 名用户。通过负载测试,我们很快发现 Spring 堆栈或 Amazon MQ 都无法很好地扩展,存在以下问题:
\n\n是的,我们增加了机器上的文件句柄等,因此 TCP 连接不是限制。Spring 不可能接近这里的限制。我们正在发送一条 18 K 的消息,用于负载,这是我们期望的最大值。在我们的结果中,消息大小几乎没有影响,它只是 Spring Stack 上的连接开销。
\n\nStompBrokerRelayMessageHandler 为每个 STOMP Connect 打开与 Broker 的连接。没有办法集中连接。因此,这使得这个 Spring 功能对于任何 \xe2\x80\x98real\xe2\x80\x99 Web 应用程序完全无用。为了支持我们的用户,用于 MQ 的 AWS 大型服务器的成本意味着该解决方案非常昂贵,需要 40 台最大的服务器。在负载测试中,Amazon MQ 机器不执行任何操作,对于 1000 个用户,它没有加载。实际上,我们所有代理只需要几台中型机器即可。
\n\n有没有人曾经使用 …
当我尝试集成 zipkin 时。它引发了这个错误
Error Msg:Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Initialization of bean failed;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkin2.server.internal.ZipkinServerConfiguration': Unsatisfied dependency expressed through field 'httpQuery';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'zipkin2.server.internal.ZipkinQueryApiV2': Bean instantiation via …Run Code Online (Sandbox Code Playgroud) 我有一个问题要问 Spring Cloud 的人。
大约。一年前,有关于 Spring Cloud RSocket 的精彩演示。其中一部分包括 Spring Cloud Gateway 中的 RSocket 支持。rsocket 经纪人。
现在我看到https://github.com/spring-cloud-incubator/spring-cloud-rsocket已经存档了。
我想知道:这是否意味着 Spring Cloud RSocket 已经死了?有替代品吗?Spring Cloud Gateway 中是否还有其他对 RSocket 的支持?或者Spring Cloud RSocket只是处于休眠状态并且有希望复活?
PS:我知道 Spring Boot 中的 RSocket 支持,这里有很好的描述。我感兴趣的是 Spring Cloud RSocket 功能,但我没有找到 Spring Boot RSocket 支持。
预期行为
根据 Spring Cloud Kubernetes 文档,Spring 应用程序检测其何时在 Pod 中运行所需要做的就是将 Spring Cloud Kubernetes 及其spring-cloud-kubernetes-all依赖项添加到类路径中。
这会触发两个事件:
application-kubernetes.yml加载配置文件。DiscoveryClient用于服务发现,利用 KubeDNS 而不是默认的 Eureka。和这里:
实际行为
使用以下 yaml 启动 Spring Cloud Kubernetes 应用程序并http://minikube-ip:port/actuator/env通过 NodePort 访问其执行器端点后,我发现没有活动配置文件集,即使文件夹application-kubernetes.yml中存在resources:
{
"activeProfiles": [],
...
Run Code Online (Sandbox Code Playgroud)
经过对http://minikube-ip:port/actuator/info端点的进一步调查,我发现 Spring 应用程序根本不知道它位于 pod 中,如下所示:
{
"kubernetes": {
"inside": false
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码
SpringCloud网关
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
@EnableDiscoveryClient …Run Code Online (Sandbox Code Playgroud) java spring spring-boot spring-cloud spring-cloud-kubernetes
我正在学习如何使用 Spring Boot 和 Spring Cloud 来使用微服务。我在选择 spring cloud 和 boot 版本时遇到问题 - 我无法使用注释,@RibbonClient因为我还没有找到依赖项。
我想使用最新版本的 spring cloud 和 spring boot,但我没有找到功能区依赖项。我想使用spring boot 2.4.1和spring cloud 2.20.0.x。
spring-cloud ×10
spring-boot ×6
spring ×4
java ×3
consul ×1
ribbon ×1
rsocket ×1
stomp ×1
zipkin ×1