Spring Reactor Consumer 不消费
Spring Reactor Consumer does not consume
今天我用下面的例子尝试了 spring 反应器:messaging-reactor
它基本上是从给定的 URL 请求随机报价并将其打印到控制台。这是一个很好的例子,展示了发布和消费如何与 spring 反应堆一起工作并且没有阻塞任何东西。
但是我有一个小问题。在示例中,定义了一个接收器(消费者),其中一个的输出如下:
Quote 4: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 6: So easy it is to switch container in #springboot.
Quote 7: Working with Spring Boot is like pair-programming with the Spring developers.
Quote 8: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 5: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 2: The real benefit of Boot, however, is that it's just Spring. That means any direction the code takes, regardless of complexity, I know it's a safe bet.
Quote 1: With Boot you deploy everywhere you can find a JVM basically.
Quote 3: With Boot you deploy everywhere you can find a JVM basically.
Quote 6: I don't worry about my code scaling. Boot allows the developer to peel back the layers and customize when it's appropriate while keeping the conventions that just work.
Quote 8: I have two hours today to build an app from scratch. @springboot to the rescue!
Elapsed time: 841ms
Average time per quote: 84ms
我添加了第二个接收器(消费者):
@Autowired
private Receiver receiver;
@Autowired
private Receiver receiver2;
@Override
public void run(String... args) throws Exception {
this.eventBus.on($("quotes"), this.receiver);
this.eventBus.on($("quotes"), this.receiver2);
this.publisher.publishQuotes(NUMBER_OF_QUOTES);
}
所以现在我有两个接收器,输出是:
Quote 4: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 6: So easy it is to switch container in #springboot.
Quote 7: Working with Spring Boot is like pair-programming with the Spring developers.
Quote 8: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 5: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 2: The real benefit of Boot, however, is that it's just Spring. That means any direction the code takes, regardless of complexity, I know it's a safe bet.
Quote 1: With Boot you deploy everywhere you can find a JVM basically.
Quote 3: With Boot you deploy everywhere you can find a JVM basically.
Quote 6: I don't worry about my code scaling. Boot allows the developer to peel back the layers and customize when it's appropriate while keeping the conventions that just work.
Quote 8: I have two hours today to build an app from scratch. @springboot to the rescue!
Elapsed time: 841ms
Average time per quote: 84ms
2017-06-25 19:15:25.137 INFO 2700 --- [ main] d.hof.fronetic.demo.reactor.Application : Started Application in 4.103 seconds (JVM running for 4.374)
Quote 7: It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.
Quote 2: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 5: Spring has come quite a ways in addressing developer enjoyment and ease of use since the last time I built an application using it.
Quote 3: So easy it is to switch container in #springboot.
Quote 1: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 10: With Boot you deploy everywhere you can find a JVM basically.
Quote 9: Previous to Spring Boot, I remember XML hell, confusing set up, and many hours of frustration.
Quote 4: Spring Boot solves this problem. It gets rid of XML and wires up common components for me, so I don't have to spend hours scratching my head just to figure out how it's all pieced together.
Quote 9: It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.
Quote 10: Spring Boot solves this problem. It gets rid of XML and wires up common components for me, so I don't have to spend hours scratching my head just to figure out how it's all pieced together.
如您所见,我现在得到 20 个引述,而不是 10 个引述。但在我看来,消费者不应该这样工作。如果我错了,请告诉我,但我认为如果消费者收到通知,它是 consuming
这条通知,这样其他接收者就无法收到这条通知。在上面的示例中,每个消费者都在执行相同的工作。如果我想在这两个消费者之间共享所有工作(打印 10 个报价)怎么办,以便在最佳情况下每个消费者将消费 5 个通知。这不就是那些publisher/consumer reactor的主要任务之一吗?
我认为您将 point to point
消息与 publish and subscribe
混淆了。您的直观模型是点对点消息传递所发生的情况,其中消费者从队列中取出一条消息,以便其他进程无法使用它。然而,基于事件的模型是不同的,因为需要一个过程将消息发布到论坛,同时通知 'all' 听众。
你有后者——一个基于事件的系统。您的听众订阅了同一频道并同时回复了相同的消息。
今天我用下面的例子尝试了 spring 反应器:messaging-reactor
它基本上是从给定的 URL 请求随机报价并将其打印到控制台。这是一个很好的例子,展示了发布和消费如何与 spring 反应堆一起工作并且没有阻塞任何东西。
但是我有一个小问题。在示例中,定义了一个接收器(消费者),其中一个的输出如下:
Quote 4: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 6: So easy it is to switch container in #springboot.
Quote 7: Working with Spring Boot is like pair-programming with the Spring developers.
Quote 8: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 5: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 2: The real benefit of Boot, however, is that it's just Spring. That means any direction the code takes, regardless of complexity, I know it's a safe bet.
Quote 1: With Boot you deploy everywhere you can find a JVM basically.
Quote 3: With Boot you deploy everywhere you can find a JVM basically.
Quote 6: I don't worry about my code scaling. Boot allows the developer to peel back the layers and customize when it's appropriate while keeping the conventions that just work.
Quote 8: I have two hours today to build an app from scratch. @springboot to the rescue!
Elapsed time: 841ms
Average time per quote: 84ms
我添加了第二个接收器(消费者):
@Autowired
private Receiver receiver;
@Autowired
private Receiver receiver2;
@Override
public void run(String... args) throws Exception {
this.eventBus.on($("quotes"), this.receiver);
this.eventBus.on($("quotes"), this.receiver2);
this.publisher.publishQuotes(NUMBER_OF_QUOTES);
}
所以现在我有两个接收器,输出是:
Quote 4: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 6: So easy it is to switch container in #springboot.
Quote 7: Working with Spring Boot is like pair-programming with the Spring developers.
Quote 8: Really loving Spring Boot, makes stand alone Spring apps easy.
Quote 5: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 2: The real benefit of Boot, however, is that it's just Spring. That means any direction the code takes, regardless of complexity, I know it's a safe bet.
Quote 1: With Boot you deploy everywhere you can find a JVM basically.
Quote 3: With Boot you deploy everywhere you can find a JVM basically.
Quote 6: I don't worry about my code scaling. Boot allows the developer to peel back the layers and customize when it's appropriate while keeping the conventions that just work.
Quote 8: I have two hours today to build an app from scratch. @springboot to the rescue!
Elapsed time: 841ms
Average time per quote: 84ms
2017-06-25 19:15:25.137 INFO 2700 --- [ main] d.hof.fronetic.demo.reactor.Application : Started Application in 4.103 seconds (JVM running for 4.374)
Quote 7: It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.
Quote 2: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 5: Spring has come quite a ways in addressing developer enjoyment and ease of use since the last time I built an application using it.
Quote 3: So easy it is to switch container in #springboot.
Quote 1: I have two hours today to build an app from scratch. @springboot to the rescue!
Quote 10: With Boot you deploy everywhere you can find a JVM basically.
Quote 9: Previous to Spring Boot, I remember XML hell, confusing set up, and many hours of frustration.
Quote 4: Spring Boot solves this problem. It gets rid of XML and wires up common components for me, so I don't have to spend hours scratching my head just to figure out how it's all pieced together.
Quote 9: It embraces convention over configuration, providing an experience on par with frameworks that excel at early stage development, such as Ruby on Rails.
Quote 10: Spring Boot solves this problem. It gets rid of XML and wires up common components for me, so I don't have to spend hours scratching my head just to figure out how it's all pieced together.
如您所见,我现在得到 20 个引述,而不是 10 个引述。但在我看来,消费者不应该这样工作。如果我错了,请告诉我,但我认为如果消费者收到通知,它是 consuming
这条通知,这样其他接收者就无法收到这条通知。在上面的示例中,每个消费者都在执行相同的工作。如果我想在这两个消费者之间共享所有工作(打印 10 个报价)怎么办,以便在最佳情况下每个消费者将消费 5 个通知。这不就是那些publisher/consumer reactor的主要任务之一吗?
我认为您将 point to point
消息与 publish and subscribe
混淆了。您的直观模型是点对点消息传递所发生的情况,其中消费者从队列中取出一条消息,以便其他进程无法使用它。然而,基于事件的模型是不同的,因为需要一个过程将消息发布到论坛,同时通知 'all' 听众。
你有后者——一个基于事件的系统。您的听众订阅了同一频道并同时回复了相同的消息。