什么是 RabbitMQ 集群?

发布于 2024-12-20 07:48:54 字数 1103 浏览 4 评论 0原文

我已经在我的 ruby​​ 项目中使用 RabbitMQ ( AMQP ) 一段时间了,无论如何我刚刚听说过 RabbitMQ 集群,任何人都可以简单地向我介绍一下它,我需要知道运行普通 RabbitMQ 服务器和 RabbitMQ 集群之间的区别,为什么需要它以及如何实现它。

我需要我的解决方案具有可扩展性并能够处理如此多的请求,我正在考虑以下实现,我很想知道如何实现这样的事情:

HA proxy->3 Clustered RabbitMQ instances

处理请求的最快方法以及最佳 ruby​​ Web 服务器选择是什么并简单地解析它并将其发送到适当的队列。

在我当前的实现中,我使用瘦服务器并执行类似以下操作,但寻找更快且更具可扩展性的更好的架构:

require "bunny"
require "thin"


@amqp ||= Bunny.new(:logging => false)
@amqp.start

@direct_exchange ||= @amqp.exchange('') 

app = Proc.new do |env|
  req = Rack::Request.new(env).params

  command = req['command'].strip rescue "no command"
  number  = req['number'].strip  rescue "no number"

  if command =~ /\A(create|c|r|register)\z/i      
    @direct_exchange.publish(number, :key => "create") 

  elsif command =~ /\A(update|u)\z/i
    @direct_exchange.publish(number , :key => "refresh") 

  end    

  [200, {'Content-Type' => "text/plain"} , command ]  

end

Rack::Handler::Thin.run(app, :Port => 4001)

我确信有更好的实现。

任何帮助/提示将不胜感激。

提前致谢

I've been using RabbitMQ ( AMQP ) with my ruby projects for a while now, anyways I just heard of RabbitMQ clustering , anyone can brief me about it is simple words , I need to know the difference between running ordinary RabbitMQ server and RabbitMQ clustering , why do I need it and how to implement it .

I need my solution to be scalable and to handle so many requests, I was thinking of the following implementation and I would love to know how to implement such a thing :

HA proxy->3 Clustered RabbitMQ instances

What is the fastest way along with the best ruby web server choice to handle request and simply parse it and send it to the appropriate queue .

With my current implementation I'm using Thin server and do something like the following but looking for better architecture which is faster and more scalable :

require "bunny"
require "thin"


@amqp ||= Bunny.new(:logging => false)
@amqp.start

@direct_exchange ||= @amqp.exchange('') 

app = Proc.new do |env|
  req = Rack::Request.new(env).params

  command = req['command'].strip rescue "no command"
  number  = req['number'].strip  rescue "no number"

  if command =~ /\A(create|c|r|register)\z/i      
    @direct_exchange.publish(number, :key => "create") 

  elsif command =~ /\A(update|u)\z/i
    @direct_exchange.publish(number , :key => "refresh") 

  end    

  [200, {'Content-Type' => "text/plain"} , command ]  

end

Rack::Handler::Thin.run(app, :Port => 4001)

I'm sure there is better implementation .

Any help/hint would be highly appreciated .

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2024-12-27 07:48:54

这完全取决于您真正的瓶颈在哪里,以及您期望的可靠性水平。但作为一般经验法则,您可能有:

  • http 负载均衡器将 http 请求平衡到多个 Web 服务器
  • N 个处理 http 请求的 Web 服务器,解析它们最终将命令发布到 RabbitMQ 节点
  • RabbitMQ 集群由 M 个兔子节点组成
  • K 个工作节点,消耗来自rabbit集群的消息和执行命令

现在http服务器的数量可以与RabbitMQ节点的数量不同。这取决于你的瓶颈在哪里。也许您只需要一个 RabbitMQ 节点(因此不需要集群)或其中几个节点。例如,如果有 2 个,则超过一半的 http 服务器将连接到一个rabbitmq 节点,另一半连接到其他节点。无论它们连接到哪个,它们都可以发布到同一个 amqp 交换,并且 rabbtimq 集群将负责处理 2 个节点并在一顶帽子下收集发布到该交换的所有内容,而与连接的节点 http 服务器无关。

同样的逻辑也适用于“workers”,即服务器消费来自rabbitmq的消息,并在其中执行命令。它们可以有 1 到 K 个,具体取决于它们需要完成多少工作。您还可以将它们均匀地连接到现有的rabbitMQ 服务器。

It all depends where your real bottlenecks are, and what level of reliability you expect. But as a general rule of the thumb you may have:

  • http load balancer balancing http request to several web servers
  • N web servers handling http requests, parsing them end publishing commands to the RabbitMQ nodes
  • RabbitMQ cluster consisting of M rabbit nodes
  • K worker nodes, consuming messages from rabbit cluster and executing commands

Now the number of http servers can be different from RabbitMQ nodes. It depends, where your bottlenecks are going to be. Maybe you would need only one RabbitMQ node (so no cluster), or a few of them. If there are 2 for instance, than half of your http servers would be connected to one rabbitmq node, and half to other. Regardless of to which they are connected, they can publish to the same amqp exchange, and rabbtimq cluster will take a care of handling 2 nodes and collecting everything published to that exchange under one hat, ragradless of the node http server was connected.

Th same logic goes for the "workers", i.e. servers consuming messages from the rabbitmq, and executing commands in them. There can be from 1 to K of them depending how much work they need to do. You would also connect them evenly to existing rabbitMQ servers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文