繁体   English   中英

具有自动配置的属性不适用于Spring Cloud Stream和Rabbitmq

[英]Properties with auto configure not working on spring cloud stream and rabbitmq

我有一个具有属性的配置服务器和一个作为使用者的微服务。

我尝试配置maxAttempts以避免在消费者微服务上重试,但似乎不起作用。

我还定义了配置服务器上的绑定属性,它们工作正常。 我的消费者正在监听并接收消息, 但是尝试3次然后崩溃。

这是我在配置服务器中的application.yml

server:
  servlet:
    contextPath: /cmsrsssitemap/v1

spring:
  cloud:
    stream:
      bindings:
        sitemap-main-output:
          destination: sitemap-main
          group: cms-microservices-v1
          content-type: application/json
          #consumer.concurrency: 2
        test-job-output:
          destination: test-job
          group: cms-microservices-v1
          content-type: application/json
      rabbit:
        bindings:
          test-job-output: 
            consumer:
              maxAttempts: 1
              requeueRejected: false
              autoBindDlq: true
              #dlqTtl: 5000
              #requeueRejected: false
              #dlqDeadLetterExchange: dltexchange1
              #republishToDlq: true

这是生产者端的application.yml

server.servlet.contextPath: /cmsjmshandler/v1

spring:
  cloud:
    stream:
      bindings:
        sitemap-main-input:         
          destination: sitemap-main
          content-type: application/json
        test-job-input:
          destination: test-job
          group: cms-microservices-v1
          content-type: application/json

这就是妙语。 它抛出一个NullPointer以进行测试

@Component
public class TestJobListener {


    @StreamListener(StreamProcessor.TEST_JOB)
    public void testJobInput(@Payload String input) throws InterruptedException {
//      Thread.sleep(3000);
        System.out.println("########################### "+new Date() + " Mensaje Recibido");
        throw new NullPointerException();
    }
}

StreamProcesor.java

public interface StreamProcessor {

    public static final String TEST_JOB = "test-job";

    public static final String SITEMAP_MAIN = "sitemap-main";


    @Input(StreamProcessor.TEST_JOB)
    SubscribableChannel testJobOutputInput();

    @Input(StreamProcessor.SITEMAP_MAIN)
    SubscribableChannel processSitemapMain();
}

这样做的目的是将失败的消息移至DLQ,但这也不起作用

编辑1:无法使其工作。 我已根据Artem Bilan进行了更改,但它也不起作用。

server:
  servlet:
    contextPath: /cmsrsssitemap/v1

spring:
  cloud:
    stream:
      bindings:
        test-job-output:
          destination: test-job
          group: cms-microservices-v1
          content-type: application/json
          consumer:
            maxAttempts: 1
      rabbit:
        bindings:
          test-job-output: 
            consumer:
              requeueRejected: false

maxAttempts不是rabbit属性。 这是一个核心。

文档中有一个有关此事的示例: https : //docs.spring.io/spring-cloud-stream/docs/Elmhurst.RELEASE/reference/htmlsingle/#spring-cloud-stream-overview-error-handling

spring.cloud.stream.bindings.input.consumer.max-attempts=1
spring.cloud.stream.rabbit.bindings.input.consumer.requeue-rejected=true

问题是我在StreamProcesor上输入了错误的名称

@StreamListener(StreamProcessor.TEST_JOB)

StreamProcesor.TEST_JOB应该是频道名称,也不应该是目的地。 更新我的问题。

更正了SteamProcesor.java StreamProcesor.java

public interface StreamProcessor {

    public static final String TEST_JOB = "test-job-output";

    public static final String SITEMAP_MAIN = "sitemap-main";


    @Input(StreamProcessor.TEST_JOB)
    SubscribableChannel testJobOutputInput();

    @Input(StreamProcessor.SITEMAP_MAIN)
    SubscribableChannel processSitemapMain();
}

我刚刚对其进行了测试,并且对我来说,使用此(更正)配置可以正常工作。 如果在客户端上启用actuator/env端点,则可以看到以下属性:

在此处输入图片说明

(我使用input和基于本地文件的配置服务器)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM