Module: OnsOnRails
- Defined in:
- lib/ons_on_rails.rb,
lib/ons_on_rails/version.rb,
lib/ons_on_rails/publisher.rb,
lib/ons_on_rails/subscriber.rb,
lib/ons_on_rails/publishers/tcp.rb,
lib/ons_on_rails/publishers/test.rb
Overview
.
Defined Under Namespace
Modules: Publishers, Subscriber Classes: Publisher
Constant Summary collapse
- VERSION =
'1.0.2'.freeze
Class Method Summary collapse
-
.create_publisher(publisher_name, backend: :tcp) ⇒ Object
Create a Publisher.
-
.logger ⇒ Object
Get the global logger.
-
.ons_default_options ⇒ Object
Get the ons default options.
-
.run_multi_subscriber_as_a_daemon(subscriber_class_name_array, app_path, options = {}) ⇒ Object
Run multi-subscribers as a separate process.
-
.run_subscriber_as_a_daemon(subscriber_class_name, app_path) ⇒ Object
Run a subscriber as a separate process.
Class Method Details
.create_publisher(publisher_name, backend: :tcp) ⇒ Object
Create a Publisher.
49 50 51 52 53 54 55 56 |
# File 'lib/ons_on_rails.rb', line 49 def self.create_publisher(publisher_name, backend: :tcp) ||= begin opts = OnsOnRails. opts.slice(:access_key, :secret_key).merge(opts.fetch(publisher_name.to_s.underscore.to_sym, {})) end OnsOnRails::Publisher.new(backend, ) end |
.logger ⇒ Object
Get the global logger.
13 14 15 |
# File 'lib/ons_on_rails.rb', line 13 def self.logger @logger ||= initialize_logger end |
.ons_default_options ⇒ Object
Get the ons default options.
25 26 27 |
# File 'lib/ons_on_rails.rb', line 25 def self. @ons_default_options ||= end |
.run_multi_subscriber_as_a_daemon(subscriber_class_name_array, app_path, options = {}) ⇒ Object
Run multi-subscribers as a separate process.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ons_on_rails.rb', line 73 def self.run_multi_subscriber_as_a_daemon(subscriber_class_name_array, app_path, = {}) daemon_name = .fetch(:daemon_name, 'subscribers') = { backtrace: true, dir_mode: :normal, dir: File.join(app_path, 'tmp', 'pids'), log_dir: File.join(app_path, 'log'), log_output: true } Daemons.run_proc(daemon_name, ) do require File.join(app_path, 'config', 'environment') require 'ons' unless defined?(Ons) subscriber_class_name_array.each do |subscriber_class_name| subscriber_class_name = subscriber_class_name.to_s.camelize subscriber_class = subscriber_class_name.constantize subscriber_class.check_subscriber_definition! = subscriber_class. Ons::Consumer.new(.fetch(:access_key), .fetch(:secret_key), .fetch(:consumer_id)) .subscribe(.fetch(:topic), .fetch(:tag), &->() { subscriber_class.consume() }) .start end Ons.register_cleanup_hooks Ons.loop_forever end end |
.run_subscriber_as_a_daemon(subscriber_class_name, app_path) ⇒ Object
Run a subscriber as a separate process.
62 63 64 65 |
# File 'lib/ons_on_rails.rb', line 62 def self.run_subscriber_as_a_daemon(subscriber_class_name, app_path) = { daemon_name: subscriber_class_name.to_s.underscore } run_multi_subscriber_as_a_daemon(Array(subscriber_class_name), app_path, ) end |