Chunked event publishing - design overview
EventCollector
Class: Roles:
#enqueue_event(payload, target queue name)
: stores messages to be sent in a simple array#publish()
send everything currently enqueued to external queue system (here: RabbitMQ); if thepublish
fails for any reason, messages are kept in memory for later retry (along with grumbling in logs, etc).#clear_events_to_publish!
is useful in rollback scenarios.thread_singleton_instance
accessor with lazy initialization, likeActiveRecord::Base.connection
. This allows for easy setup, and persistent state across requests (should flushing fail we can retry on next request on the same thread). Thethread_singleton_instance
also easy replacement with a simple test implementation, thinkActionMailer
. Sending actual messages in test is best restricted to a few integration test scenarios.