Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6334365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:38:43+00:00 2026-05-24T18:38:43+00:00

Is it possible to start an AMQP subscriber with my Rails app? Possibly through

  • 0

Is it possible to start an AMQP subscriber with my Rails app? Possibly through an initializer or something.

I’d like to have it running at the same time that can also interact with Rails models. Below is a pseudo-code example of what I mean.

queue.subscribe do |msg,body|
  Foo.create(....)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:38:44+00:00Added an answer on May 24, 2026 at 6:38 pm

    I usually do this via a separate messaging daemon which loads the rails environment.

    So a very simplistic example would look like this in rails_root/script/myapp_daemon.rb :

    
    
        #!/usr/bin/env ruby
        require 'rubygems'
        require 'amqp'
        require 'daemons'
    
        ENV["RAILS_ENV"] ||= "development"
        require File.dirname(__FILE__) + "/../config/environment"
    
        options = { :backtrace => true, :dir => '.', :log_output => true}
    
        Daemons.run_proc('myapp_daemon', options) do
          EventMachine.run do
            connection = AMQP.connect(:host => "127.0.0.1")
    
            channel = AMQP::Channel.new(connection)
            queue    = channel.queue("/myapp_daemon", :durable => true)
            exchange = channel.direct("")
    
            queue.subscribe do |payload|
              obj = JSON.parse(payload)
              #... handle messages here, utilize your rails models
              Foo.create(...)
            end
          end
        end
    
    

    You would also need the right gem requires in your Gemfile: amqp, daemons, eventmachine

    Then either run it manually alongside your app:

    RAILS_ENV=development script/myapp_daemon.rb run
    

    Or start it from one of your app initializers:

    system('script/myapp_daemon.rb start')
    

    To dig into amqp check out the following, this will give a nice high level overview:
    http://www.rubyinside.com/why-rubyists-should-care-about-messaging-a-high-level-intro-5017.html

    This gives a very detailed explanation with working examples:
    http://rubydoc.info/github/ruby-amqp/amqp/master/file/docs/Exchanges.textile#Publishing_messages_as_immediate_

    Finally see if Bunny accomplishes everything you need for the client, it is simpler:
    https://github.com/celldee/bunny/wiki/Using-Bunny

    Hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible start a new thread within an Async task? Something like this:
Is it possible to start Tomcat with only the Manager webapp running? I have
Is it possible to start an array at an index not zero...I.E. you have
Is it possible to start an FB session in an iPhone app without using
As Rails applications default run on port 3000, would it be possible to start
Is it possible to start up an app when a iOS device starts up,
It it possible to start an adobe air apk from my current android app?
Hello is it possible to start like too many activities during the runtime of
Im creating a news-like app and I want to know is is possible to
Is it possible to start a webpages scroll from the bottom, I have gotten

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.