简体   繁体   English

带有RabbitMQ的春季云流

[英]Spring cloud stream with RabbitMQ

Currently, in my project, I'm using spring cloud stream with rabbitmq. 目前,在我的项目中,我正在使用Rabbitmq的Spring Cloud Stream。 Everything is okay, but the problem is when in StreamListener I set a condition for the message type. 一切都很好,但是问题是当我在StreamListener中为消息类型设置条件时。 If RabbitMQ doesn't match type (Cannot find a @StreamListener matching for a message with id: ZZZZZZ) then this message disappeared from the queue. 如果RabbitMQ与类型不匹配(找不到ID为ZZZZZZ的消息的@StreamListener匹配项),则此消息将从队列中消失。 I don't want to remove this message if the message has a bad type. 如果邮件类型错误,我不想删除此邮件。 Is some solution for this problem? 这个问题有解决方案吗?

There are two ways you can do it: 有两种方法可以做到:

  • Throw an exception if the message has bad type. 如果消息的类型错误,则引发异常。 In this case, the message will not be removed from the queue since it wasn't processed successfully and no ACK was received. 在这种情况下,由于未成功处理消息且未收到ACK,因此不会从队列中删除该消息。
  • Insert the message in the queue yourself once you have detected the type is bad. 一旦检测到类型错误,就可以自己将消息插入队列中。

Both approaches can suffer what is called an infinite loop. 两种方法都可能遭受无限循环的困扰。 The message is processed, it is of bad type, it is re-inserted, and this repeats. 消息已处理,类型错误,重新插入,然后重复此过程。 To avoid this you can add some policy of reinserting, like: exponenetial delay, or a limited number of re-insertions etc. 为了避免这种情况,您可以添加一些重新插入策略,例如:指数延迟或有限数量的重新插入等。

But some doubt arises: why is your service consuming messages that it shouldn't? 但是会引起一些疑问:为什么您的服务会消耗本不应该的消息? Perhaps you need a specific processor this messages? 也许您需要特定处理器的此消息? In this case you can route to the suitable processor. 在这种情况下,您可以路由到合适的处理器。

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

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