【问题标题】:Spring cloud stream RabbitMq - Set properties from source codeSpring Cloud Stream RabbitMq - 从源代码设置属性
【发布时间】:2019-12-23 09:34:17
【问题描述】:

我正在使用带有 RabbitMQ 的 Spring 云流。

我希望能够从源代码而不是从属性文件(正如他们在文档中提到的那样)配置消息和查询属性。

例如,使用 RabbitMq 的经典 Java 客户端,我可以执行类似的操作来创建具有我想要的属性的队列:

                    //qName,    passive, durable, exclusive  auto-delete
channel.queueDeclare("myQueue", true,    false,   false,   , false       , null);

关于如何使用 Spring Cloud Stream 实现相同目标的任何想法?

【问题讨论】:

    标签: java spring rabbitmq spring-cloud


    【解决方案1】:

    在“application.yml”中你可以添加所有这些值,下面是例子

    spring:
      cloud:
        stream:
          instance-count: 1
          bindings:
            input:
              consumer:
                concurrency: 2
                maxAttempts: 1
              group: geode-sink
              destination: jdbc-event-result
              binder: rabbit
          rabbit:
            bindings:
              input:
                consumer:
                  autoBindDlq: true
                  republishToDlq: true
                  requeueRejected: false
    
    rabbitmq:
        username: ur-user-name
        password: ur-password
        host: rabbitmq-url-replace-here
        port: 5672
    datasource:
      platform: mysql
      url: jdbc:mysql-url-replace-here
      username: ur-user-name
      password: ur-password
      driverClassName: com.mysql.jdbc.Driver
    
      datasource:
        tomcat:
          max-wait:  300
          min-idle: 10
          max-idle: 100
    
    aggregator:
      groupCount: 2
      batchSize: 1000
      batchTimeout: 1000
    

    更新:

    【讨论】:

    • 感谢您的回答,但据我所知,您的回答不包含我想要的信息。我希望能够修改查询和消息属性。例如,我怎样才能使查询成为非持久和非排他性的。有没有办法从内部源代码而不是从属性文件中实现它?
    【解决方案2】:

    在挖掘他们的文档并在@vaquar khan 的帮助下,我发现唯一的方法是从您的属性文件中。

    application.yml

    spring:
      cloud:
        stream:
          bindings:
            queue_name :
              destination: queue_name
              group: your_group_name 
              durable-subscription : true
    

    这将声明一个持久的、非删除的和非独占的队列。

    【讨论】:

      猜你喜欢
      • 2021-05-07
      • 2018-01-24
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 2021-03-25
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      相关资源
      最近更新 更多