简体   繁体   English

生产者和消费者如何绑定Spring云stream绑定?

[英]How to bind Spring cloud stream binding for producer and consumer?

I am new to Spring cloud and RabbitMQ. I am trying to produce and consume messages from Rabbit MQ.我是 Spring 云和 RabbitMQ 的新手。我正在尝试从 Rabbit MQ 生成和使用消息。 I am having difficulty in configuring exchange name and queue name for producer and consumer.我在为生产者和消费者配置交换名称和队列名称时遇到困难。

I want to connect to the existing exchange called to order and the existing queue called myQueue我想连接到名为order的现有交换和名为myQueue的现有队列

Below is the application.properties下面是 application.properties

 spring.rabbitmq.addresses=amqp://user:pass@localhost:5672/ spring.cloud.stream.function.bindings.processTable-out-0=order spring.cloud.stream.function.bindings.processTable-in-0=order spring.cloud.stream.bindings.order.group=myQueue spring.cloud.stream.bindings.order.content-type=application/json

Above configuration is connecting to order exchange, however, it is creating and connecting a new queue called order.myQueue .上面的配置连接到order交换,但是,它正在创建并连接一个名为order.myQueue的新队列。

The consumer method is below.消费者方法如下。

  @Bean
  public Consumer<String> processTable(){
      log.info("Conuming message......................");
      Consumer<String> consumer = (request)-> System.out.println(request);
      System.out.println(consumer);
      return consumer;
  }

What do I need to tweak in application.properties to connect to order exchange and myOrder queue?我需要在application.properties中进行哪些调整才能连接到order交换和myOrder队列?

See Using Existing Queues/Exchanges .请参阅使用现有队列/交换

If you have an existing exchange/queue that you wish to use, you can completely disable automatic provisioning as follows, assuming the exchange is named myExchange and the queue is named myQueue:如果您有想要使用的现有交换器/队列,则可以完全禁用自动配置,如下所示,假设交换器名为 myExchange,队列名为 myQueue:

  • spring.cloud.stream.bindings..destination=myExchange spring.cloud.stream.bindings..destination=myExchange

  • spring.cloud.stream.bindings..group=myQueue spring.cloud.stream.bindings..group=myQueue

  • spring.cloud.stream.rabbit.bindings..consumer.bindQueue=false spring.cloud.stream.rabbit.bindings..consumer.bindQueue=false

  • spring.cloud.stream.rabbit.bindings..consumer.declareExchange=false spring.cloud.stream.rabbit.bindings..consumer.declareExchange=false

  • spring.cloud.stream.rabbit.bindings..consumer.queueNameGroupOnly=true spring.cloud.stream.rabbit.bindings..consumer.queueNameGroupOnly=true

暂无
暂无

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

相关问题 使用Spring Cloud Stream将RabbitMQ使用者绑定到RabbitMQ生产者 - Bind RabbitMQ consumer using Spring Cloud Stream to RabbitMQ producer 多云应用程序中的Spring Cloud Stream DLQ,生产者和消费者 - Spring Cloud Stream DLQ, Producer and Consumer Residing under Multiple Application Spring 云 Stream 与 RabbitMQ 绑定器和事务性消费者/生产者与 DB 操作 - Spring Cloud Stream with RabbitMQ binder and Transactional consumer/producer with DB operations 使用Spring Cloud Stream将RabbitMQ消费者绑定到现有队列 - Bind RabbitMQ consumer using Spring Cloud Stream to an existing queue Spring Cloud Stream 不会向 RabbitMQ 发送消息,而是在同一个 pod 中消费。 生产者和消费者在同一个应用程序中 - Spring Cloud Stream is not sending messages to RabbitMQ, instead consumes in the same pod. Producer and Consumer are in the same app Spring 云 Stream 3 RabbitMQ 消费者不工作 - Spring Cloud Stream 3 RabbitMQ consumer not working 如何在Spring Boot Rabbitmq中分别配置生产者和消费者? - How to separately configure producer and consumer in spring boot rabbitmq? Spring Cloud Stream RabbitMQ Binder Consumer Properties republishToDlq 对我不起作用 - Spring Cloud Stream RabbitMQ Binder Consumer Properties republishToDlq not working for me 使用Spring Cloud Stream定义RabbitMQ的消费者标签 - Defining Consumer Tag for RabbitMQ using Spring Cloud Stream 当消费者在spring-cloud-stream应用中启动时接收消息 - Receive message when consumer is up in spring-cloud-stream app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM