我有下一个代码:
# Gemfile
gem 'sneakers'
# application.rb
config.active_job.queue_adapter = :sneakers
# application_mailer.rb
class ApplicationMailer < ActionMailer::Base
...
def send_letter(params={})
mail(params)
...
end
end
# my_mailer_controller.rb
def send_my_mail
ApplicationMailer.send_letter(params).deliver_later
end
rabbitmq-server 已安装并启动。当我运行 'send_my_mail' 函数时,我在 Rails 控制台消息中收到:
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: b2c66a30-70d1-4bba-a88e-d6260443347d) to Sneakers(mailers) with arguments: "ApplicationMailer", "send_letter", "deliver_now", ...
但是当我使用终端命令运行 ActiveJob 工作者时:
WORKERS=ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper rake sneakers:run
什么都没发生。看起来具有正确类名的邮件侦听器未启动,因此未发送信件。在 Rabbitmq UI 跟踪器中,我看到了消息事件的记录:
Node: rabbit@ubuntu-trusty-64
Connection: 127.0.0.1:35834 -> 127.0.0.1:5672
Virtual host: /
User: guest
Channel: 1
Exchange: sneakers
Routing keys: [<<"mailers">>]
Routed queues: []
Properties: [{<<"priority">>,signedint,0},
{<<"delivery_mode">>,signedint,2},
{<<"content_type">>,longstr,<<"application/octet-stream">>}]
Payload:
{"job_class":"ActionMailer::DeliveryJob","job_id":"7a58ab27-d110-4e8b-911b-fe821735e1b7","queue_name":"mailers","arguments":["ApplicationMailer","send_newsletter","deliver_now",...
'deliver_later' Active Job 和 Sneakers 的正确工人名称是什么?谢谢你。