Class: Contrast::Api::Communication::MessagingQueue
- Inherits:
-
Contrast::Agent::WorkerThread
- Object
- Contrast::Agent::WorkerThread
- Contrast::Api::Communication::MessagingQueue
- Includes:
- Components::Interface
- Defined in:
- lib/contrast/api/communication/messaging_queue.rb
Overview
Top level gateway to messaging with speedracer
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#speedracer ⇒ Object
readonly
Returns the value of attribute speedracer.
Instance Method Summary collapse
-
#initialize ⇒ MessagingQueue
constructor
A new instance of MessagingQueue.
-
#send_event_eventually(event) ⇒ Object
Use this to add a message to the queue and process the response internally.
-
#send_event_immediately(event) ⇒ Object
Use this to bypass the messaging queue and leave response processing to the caller.
- #start_thread! ⇒ Object
Methods included from Components::Interface
Methods inherited from Contrast::Agent::WorkerThread
Constructor Details
#initialize ⇒ MessagingQueue
Returns a new instance of MessagingQueue.
17 18 19 20 21 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 17 def initialize @queue = Queue.new @speedracer = Contrast::Api::Communication::Speedracer.new super end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
15 16 17 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 15 def queue @queue end |
#speedracer ⇒ Object (readonly)
Returns the value of attribute speedracer.
15 16 17 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 15 def speedracer @speedracer end |
Instance Method Details
#send_event_eventually(event) ⇒ Object
Use this to add a message to the queue and process the response internally
29 30 31 32 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 29 def send_event_eventually event logger.debug('Enqueued event for sending', event_type: event.cs__class) queue << event if event end |
#send_event_immediately(event) ⇒ Object
Use this to bypass the messaging queue and leave response processing to the caller
24 25 26 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 24 def send_event_immediately event send_event(event, true) end |
#start_thread! ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/contrast/api/communication/messaging_queue.rb', line 34 def start_thread! speedracer.ensure_startup! return if running? @_thread = Contrast::Agent::Thread.new do loop do event = queue.pop begin logger.debug('Dequeued event for sending', event_type: event.cs__class) send_event(event) rescue StandardError => e logger.error('Could not send message to service from messaging queue thread.', e) end end end logger.debug('Started background sending thread.') end |