如何在rails应用程序的后台监听AWS SQS消息?

我想在rails应用程序的后台异步轮询消息。 Shoryuken不起作用,因为我希望我的rails应用程序也能监听传入的HTTP请求。

config/initializers创建一个初始化config/initializers如下所示:

 # Allows the thread to crash our app for us Thread.abort_on_exception = true Thread.new do queue_url = "..." poller = Aws::SQS::QueuePoller.new(queue_url) poller.poll do |msg| puts msg.body end end 

您可以使用Active Job通过更复杂的作业处理消息:

像这样创建工作: rails g job process_a_message

然后在poller块中:

  poller.poll do |msg| ProcessAMessageJob.perform_later msg.body end 
Interesting Posts