标签: spring-cloud

针对不同消费者的每条消息的 Spring Cloud Stream 主题

我正在寻找的拓扑是

在此输入图像描述

到目前为止,我还没有看到在 Cloud Stream 中定义每条消息的主题的方法。我知道消费者将绑定到特定主题,但是生产者在将消息发送到交换器之前如何设置每条消息的主题?

source.output().send(MessageBuilder.withPayload(myMessage).build());
Run Code Online (Sandbox Code Playgroud)

不提供任何方法来设置交换的主题以路由到正确的消费者。

或者也许我不理解正确的东西?

更新

我希望不会在消费者中收到消息,因为bindingRoutingKey2222正在发送routeTo 1111. 但我仍然在消费者身上收到它。

生产者属性:

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

spring.cloud.stream.bindings.output.content-type=application/json
spring.cloud.stream.bindings.output.destination=messageExchange
spring.cloud.stream.rabbit.bindings.output.producer.routing-key-expression=headers['routeTo']


@EnableBinding(Source.class)
@SpringBootApplication
public class Application {

   public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

}
Run Code Online (Sandbox Code Playgroud)

发件人:

source.output().send(MessageBuilder.withPayload(mo).setHeader("routeTo", "1111").build());

以及消费者:

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

spring.cloud.stream.bindings.input.destination=messageExchange
spring.cloud.stream.rabbit.bindings.input.consumer.bindingRoutingKey=2222
Run Code Online (Sandbox Code Playgroud)

应用:

@SpringBootApplication
@EnableBinding(Sink.class)
public class Application {

private static final Logger log = LoggerFactory.getLogger(Application.class);

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

@StreamListener(Sink.INPUT)
public void ReceiveMo(String moDTO) …
Run Code Online (Sandbox Code Playgroud)

spring spring-cloud spring-cloud-stream

2
推荐指数
1
解决办法
1630
查看次数

在数据库中保留 Spring Cloud Gateway 路由

我目前正在使用spring cloud gateway项目构建简单的api网关,计划是将路由持久化到mongodb中,然后刷新,以便新路由可用。我做了这样简单的事情来从 mongo 获取我的路线。

@Bean
public RouteLocator routeLocator(RouteLocatorBuilder builder){
    List<CreateAPIRequest> apiRequestList = repository.findAll();
    RouteLocatorBuilder.Builder routeLocator = builder.routes();
    for (CreateAPIRequest request: apiRequestList) {
        routeLocator
        .route(r-> {
              r.path("/"+request.getProxy().getListenPath())
             .filters(f->f.stripPrefix(1))
             .uri(request.getProxy().getTargetUrl()) 
        });
    }
    return routeLocator.build();
}
Run Code Online (Sandbox Code Playgroud)

我能够在数据库中创建新路线,但无法即时刷新。

我需要了解如何动态刷新路线。

谢谢

spring-boot spring-cloud spring-cloud-gateway

2
推荐指数
2
解决办法
5778
查看次数

部署为 WAR 时 Spring Cloud Gateway 未启动,显示 webFluxConversionService 错误

我正在尝试使用 Spring Cloud Gateway 做一个示例,用于 JWT 身份验证和 URL 路由目的。

当我作为 JAVA 应用程序运行或使用嵌入式 Tomcat 容器时,一切运行良好,但当将其作为 War 部署到 Tomcat 服务器时,我会出现以下依赖项注入错误。


应用程序无法启动


描述:

org.springframework.cloud.gateway.config.GatewayAutoConfiguration 中的方法routeDefinitionRouteLocator 的参数4 需要一个类型为“org.springframework.core.convert.ConversionService”的bean,但无法找到。

注入点有以下注释: - @org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)

行动:

考虑在配置中定义“org.springframework.core.convert.ConversionService”类型的 bean。

我尝试添加与 Spring Web Flux 相关的 jar,但错误没有消失

我的 POM.XML

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.gateway</groupId>
    <artifactId>gateway</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <name>gateway</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR2</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
    <groupId>javax.servlet</groupId> …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud spring-webflux

2
推荐指数
1
解决办法
4518
查看次数

带有 Spring Boot 的 Cloud Kafka 给我错误

嘿,我按照分步指南在 Spring Boot 中设置 kafka。

但现在我无法启动该应用程序。有什么建议 :)

日志中的错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'functionInitializer' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Found more then one function in BeanFactory: [persistentEntities, resourceMappings]. Consider providing 'spring.cloud.function.definition' property.
Run Code Online (Sandbox Code Playgroud)

什么是 spring.cloud.function.definition?以及如何设置呢?引起原因:java.lang.IllegalArgumentException:在 BeanFactory 中发现多个函数:[persistentEntities,resourceMappings]。考虑提供“spring.cloud.function.definition”属性。

java spring-boot spring-cloud spring-cloud-stream spring-cloud-function

2
推荐指数
1
解决办法
4673
查看次数

Spring Boot 管理列出 kubernetes 内部 url。无法导航至应用程序页面

问题

  • 尝试使用 Spring boot admin 对 Kubernetes 中运行的 Spring Boot 微服务进行深度监控。
  • Spring Boot 管理列出了微服务,但指向内部 IP。

显示内部 IP 的 Spring Boot 管理应用程序列表页面

显示内部 IP 的 Spring Boot 管理应用程序列表页面

应用程序详细信息页面几乎为零信息

应用详情页面几乎为零信息

细节

  • 库伯内特斯 1.15
  • Spring boot 管理员使用 Spring cloud discovery 发现 Spring boot 应用程序
  • spring-cloud-kubernetes 版本 1.1.0.RELEASE
  • 问题是 IP 属于内部 Pod 网络,在任何现实场景中用户都无法访问。

关于如何处理这种情况有任何提示吗?还有其他选择吗?

我还想知道如果 Pod 具有多个副本,Spring Boot 管理员会如何表现。我认为通过入口或节点端口指向唯一的 Pod 副本几乎是不可能的。

我正在研究的黑客

如果我可以启动另一个 pod,将 Linux 桌面公开给最终用户。从该桌面的浏览器中,用户可以访问 pod 网络 ip。作为黑客,这只是一个疯狂的想法。

spring-boot kubernetes microservices spring-cloud spring-boot-admin

2
推荐指数
1
解决办法
3440
查看次数

jhipster应用程序的JWT认证

我生成了两个 jhipster 应用程序:微服务网关和选择使用 JWT 保护它的微服务应用程序。授权工作方式为例外,这意味着当我以微服务网关的用户身份登录时,它会发送一个令牌,并使用此令牌我可以向微服务应用程序authentication token发出直接请求以访问受保护的资源。

问题是,即使生成的应用程序中的密钥不同,微服务应用程序如何正确验证 JWT 令牌?jhipster.security.authentication.jwt.base64-secret

java jwt jhipster microservices spring-cloud

2
推荐指数
1
解决办法
2771
查看次数

DefaultMessageListenerContainer 停止处理消息

我希望这是一个简单的配置问题,但我似乎无法弄清楚它可能是什么。

设置

  • Spring-Boor 2.2.2.RELEASE
  • 云启动器
  • 云启动器 aws
  • 弹簧JMS
  • spring-cloud-依赖项 Hoxton.SR1
  • 亚马逊-sqs-java-messaging-lib 1.0.8

问题

我的应用程序启动正常并开始处理来自 Amazon SQS 的消息。一段时间后,我看到以下警告

2020-02-01 04:16:21.482 LogLevel=WARN 1 --- [ecutor-thread14] osjlDefaultMessageListenerContainer:计划的消费者数量已降至并发消费者限制以下,可能是由于任务被拒绝。检查你的线程池配置!由剩余消费者触发自动恢复。

上述警告被打印多次,最终我看到以下两条信息消息

2020-02-01 04:17:51.552 LogLevel=INFO 1 --- [ecutor-thread40] casjavamessaging.SQSMessageConsumer :关闭 ConsumerPrefetch 执行器

2020-02-01 04:18:06.640 LogLevel=INFO 1 --- [ecutor-thread40] com.amazon.sqs.javamessaging.SQSSession :关闭 SessionCallBackScheduler 执行程序

上述 2 条消息将显示多次,并且在某个时刻,SQS 不再消耗任何消息。我在日志中没有看到任何其他消息表明存在问题,但我没有从处理程序收到任何消息表明它们正在处理消息(我有 2 个~),并且我可以看到 AWS SQS 队列的消息数量不断增长,并且年龄。

~:当我有一个处理程序时,这个确切的代码工作正常,当我添加第二个处理程序时,这个问题就开始了。

配置/代码

我意识到的第一个“警告”是由ThreadPoolTask​​Executor的货币引起的,但我无法获得正常工作的配置。这是我当前的 JMS 配置,我尝试了各种级别的最大池大小,除了根据池大小迟早启动警告之外,没有任何实际影响

    public ThreadPoolTaskExecutor asyncAppConsumerTaskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setThreadGroupName("asyncConsumerTaskExecutor");
        taskExecutor.setThreadNamePrefix("asyncConsumerTaskExecutor-thread");
        taskExecutor.setCorePoolSize(10);
        // Allow the thread pool …
Run Code Online (Sandbox Code Playgroud)

spring amazon-sqs amazon-web-services spring-jms spring-cloud

2
推荐指数
1
解决办法
1977
查看次数

Keycloak 与 Spring Cloud Gateway

我尝试使用 Keycloak Spring Boot Adapter 来保护我的 Spring Cloud Gateway。添加依赖项后,它立即向我显示此错误keycloak-spring-boot-starter

**********************************************************

Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

**********************************************************
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gatewayConfigurationService' defined in class path resource [org/springframework/cloud/gateway/config/GatewayAutoConfiguration.class]: Unsatisfied dependency expressed through method 'gatewayConfigurationService' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.core.convert.ConversionService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=webFluxConversionService)}
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798) …
Run Code Online (Sandbox Code Playgroud)

spring spring-boot spring-cloud keycloak spring-cloud-gateway

2
推荐指数
1
解决办法
3288
查看次数

使用凭证的 Spring Cloud Config 和 Github 存储库

我正在尝试访问位于企业防火墙(开放 VPN)后面的 Github 存储库。我尝试使用我的用户名和密码进行访问,但出现以下异常。有关如何使用 Spring Cloud 访问存储库的任何建议。

应用程序属性:

spring.cloud.config.server.git.uri=https://github.com/company-repo/abc.git
spring.cloud.config.server.git.username=tarun
spring.cloud.config.server.git.password=xxxxx
spring.cloud.config.server.git.ignore-local-ssh-settings=true
Run Code Online (Sandbox Code Playgroud)

例外:

Error occured cloning to base directory. org.eclipse.jgit.api.errors.TransportException:
 https://github.com/company-repo/abc.git: not authorized
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud

2
推荐指数
2
解决办法
3062
查看次数

Spring Cloud Gateway Predicate 中的 matchOptionalTrailingSeparator 有什么用

来自 Spring.io 给出的有关 Spring Cloud 的文档: 在此输入图像描述

路径路由谓词工厂采用两个参数:Spring PathMatcher 模式列表和名为 matchOptionalTrailingSeparator 的可选标志。

它提到了一个可选标志,matchOptionalTrailingSeparator但没有更多描述。

这个标志有什么用以及如何使用这个标志?谢谢

spring spring-cloud spring-cloud-gateway

2
推荐指数
1
解决办法
1506
查看次数