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 8518927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:06:40+00:00 2026-06-11T06:06:40+00:00

I have an application that reacts to messages sent by clients. One message is

  • 0

I have an application that reacts to messages sent by clients. One message is reload_credentials, that the application receives any time a new client registers. This message will then connect to a PostgreSQL database, do a query for all the credentials, and then store them in a regular Ruby hash ( client_id => client_token ).

Some other messages that the application may receive are start,stop,pause which are used to keep track of some session times. My point is that I envision the application functioning in the following way:

  • client sends a message
  • message gets queued
  • queue is being processed

However, for example, I don’t want to block the reactor. Furthermore, let’s imagine I have a reload_credentials message that’s next in queue. I don’t want any other message from the queue to be processed until the credentials are reloaded from the DB. Also, while I am processing a certain message ( like waiting for the credentials query to finish) , I want to allow other messages to be enqueued .

Could you please guide me towards solving such a problem? I’m thinking I may have to use em-synchrony, but I am not sure.

  • 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-06-11T06:06:42+00:00Added an answer on June 11, 2026 at 6:06 am

    Use one of the Postgresql EM drivers, or EM.defer so that you won’t block the reactor.

    When you receive the ‘reload_credentials’ message just flip a flag that causes all subsequent messages to be enqueued. Once the ‘reload_credentials’ has finished, process all messages from the queue. After the queue is empty flip the flag that causes messages to be processed as they are received.

    EM drivers for Postgresql are listed here: https://github.com/eventmachine/eventmachine/wiki/Protocol-Implementations

    module Server
      def post_init
        @queue               = []
        @loading_credentials = false
      end
    
      def recieve_message(type, data)
        return @queue << [type, data] if @loading_credentials || !@queue.empty?
        return process_msg(type, data) unless :reload_credentials == type
        @loading_credentials = true
        reload_credentials do
          @loading_credentials = false
          process_queue
        end
      end
    
      def reload_credentials(&when_done)
        EM.defer( proc { query_and_load_credentials }, when_done )
      end
    
    
      def process_queue
        while (type, data = @queue.shift)
          process_msg(type, data)
        end
      end
    
      # lots of other methods
    end
    
    EM.start_server(HOST, PORT, Server)
    

    If you want all connections to queue messages whenever any connection receives a ‘reload_connections’ message you’ll have to coordinate via the eigenclass.

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

Sidebar

Related Questions

I have an Android application that works with sms messages. When new sms message
I have application that brings response via Ajax and creates 5-20 new jQuery click
I have created a gaming application that has only one window. Application is created
For an application I have to use a custom button that react when one
I'm currently trying to write an application that intercepts text messages and reacts depending
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I am building a Rails application that contains Developer s who have Application s.
I have an application that goes like this F5 load balancer - IHS(a&b) -

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.