Skip to content

Instantly share code, notes, and snippets.

@Paxa
Created July 13, 2017 09:29
Show Gist options
  • Save Paxa/36a332261f5255d20ef83868738204ab to your computer and use it in GitHub Desktop.
Save Paxa/36a332261f5255d20ef83868738204ab to your computer and use it in GitHub Desktop.
rabbit migrate
desc "Create rabbitmq setup"
task :setup_rabbit => :environment do
QueueWorker::HostSelector.mute_logger
Rails.logger = Logger.new(STDOUT)
options = {}
if ENV['UNDO']
options = {delete_all: true, raise_errors: false}
end
if ENV['RECREATE']
options = {recreate_things: true, raise_errors: false}
end
RabbitDeclare.new(options) do
### ALTEA
add_exchanges(:sch_pending_exchange, :sch_fail_exchange, :sch_retry_exchange)
add_queue(:sch_pending, durable: true, arguments: {
"x-message-ttl": 300.seconds,
"x-dead-letter-exchange": "sch_pending_exchange",
"x-dead-letter-routing-key": "sch_inbox"
})
add_queue(:sch_working, durable: true, arguments: {
"x-dead-letter-exchange": "sch_fail_exchange",
"x-dead-letter-routing-key": "sch_to_retry"
})
add_queue(:sch_retry, durable: true, arguments: {
"x-message-ttl": 300.seconds,
"x-dead-letter-exchange": "sch_retry_exchange",
"x-dead-letter-routing-key": "sch_to_work"
})
add_binding(source: :sch_pending_exchange, destination: ["queue", "sch_working"], routing_key: "sch_inbox")
add_binding(source: :sch_fail_exchange, destination: ["queue", "sch_retry"], routing_key: "sch_to_retry")
add_binding(source: :sch_retry_exchange, destination: ["queue", "sch_working"], routing_key: "sch_to_work")
### KEEPALICE
add_exchanges(:keepalive_towork_exchange, :keepalive_failed_exchange)
add_queue(:keepalive_working, durable: true, arguments: {
"x-dead-letter-exchange": "keepalive_failed_exchange",
"x-dead-letter-routing-key": "ka_to_retry"
})
add_queue(:keepalive_pending, durable: true, arguments: {
"x-message-ttl": 240.seconds,
"x-dead-letter-exchange": "keepalive_towork_exchange",
"x-dead-letter-routing-key": "ka_inbox"
})
add_binding(source: :keepalive_towork_exchange, destination: ["queue", "keepalive_working"], routing_key: "ka_inbox")
add_binding(source: :keepalive_towork_exchange, destination: ["queue", "keepalive_working"], routing_key: "ka_inbox")
add_binding(source: :keepalive_failed_exchange, destination: ["queue", "keepalive_pending"], routing_key: "ka_to_retry")
### CALL CONFIRM URL
add_exchanges(:call_confirm_url_pending_exchange, :call_confirm_url_fail_exchange, :call_confirm_url_retry_exchange)
add_queue(:call_confirm_url_pending, durable: true, arguments: {
"x-message-ttl": 60.seconds,
"x-dead-letter-exchange": "call_confirm_url_pending_exchange",
"x-dead-letter-routing-key": "call_confirm_url_inbox"
})
add_queue(:call_confirm_url_working, durable: true, arguments: {
"x-dead-letter-exchange": "call_confirm_url_fail_exchange",
"x-dead-letter-routing-key": "call_confirm_url_to_retry"
})
add_queue(:call_confirm_url_retry, durable: true, arguments: {
"x-message-ttl": 60.seconds,
"x-dead-letter-exchange": "call_confirm_url_retry_exchange",
"x-dead-letter-routing-key": "call_confirm_url_to_work"
})
add_binding(source: :call_confirm_url_pending_exchange, destination: ["queue", "call_confirm_url_working"], routing_key: "call_confirm_url_inbox")
add_binding(source: :call_confirm_url_fail_exchange, destination: ["queue", "call_confirm_url_retry"], routing_key: "call_confirm_url_to_retry")
add_binding(source: :call_confirm_url_retry_exchange, destination: ["queue", "call_confirm_url_working"], routing_key: "call_confirm_url_to_work")
### GOS NOTIFICATIONS
add_exchanges(:gos_fail_exchange, :gos_retry_exchange)
add_queue(:gos_working, durable: true, arguments: {
"x-dead-letter-exchange": "gos_fail_exchange",
"x-dead-letter-routing-key": "gos_to_retry"
})
add_queue(:gos_working, durable: true, arguments: {
"x-dead-letter-exchange": "gos_fail_exchange",
"x-dead-letter-routing-key": "gos_to_retry"
})
add_queue(:gos_retry, durable: true, arguments: {
"x-message-ttl": 60.seconds,
"x-dead-letter-exchange": "gos_retry_exchange",
"x-dead-letter-routing-key": "gos_to_work"
})
add_binding(source: :gos_fail_exchange, destination: ["queue", "gos_retry"], routing_key: "gos_to_retry")
add_binding(source: :gos_retry_exchange, destination: ["queue", "gos_working"], routing_key: "gos_to_work")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment