Class: ActiveEvent::EventServer
- Inherits:
-
Object
- Object
- ActiveEvent::EventServer
- Includes:
- Singleton
- Defined in:
- lib/active_event/event_server.rb
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #event_channel ⇒ Object
- #event_connection ⇒ Object
- #event_exchange ⇒ Object
- #listen_for_resend_requests ⇒ Object
- #resend_events_after(id) ⇒ Object
- #resend_request_exchange ⇒ Object
- #resend_request_queue ⇒ Object
- #resend_request_received(id) ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#options ⇒ Object
66 67 68 |
# File 'lib/active_event/event_server.rb', line 66 def @options end |
Class Method Details
.publish(event) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/active_event/event_server.rb', line 7 def self.publish(event) type = event.class.name body = event.to_json instance.event_exchange.publish body, type: type, headers: event.store_infos puts "Published #{type} with #{body}" end |
.start(options) ⇒ Object
14 15 16 17 |
# File 'lib/active_event/event_server.rb', line 14 def self.start() instance. = instance.start end |
Instance Method Details
#event_channel ⇒ Object
50 51 52 |
# File 'lib/active_event/event_server.rb', line 50 def event_channel @event_channel ||= event_connection.create_channel end |
#event_connection ⇒ Object
46 47 48 |
# File 'lib/active_event/event_server.rb', line 46 def event_connection @event_server ||= Bunny.new URI::Generic.build([:event_connection]).to_s end |
#event_exchange ⇒ Object
54 55 56 |
# File 'lib/active_event/event_server.rb', line 54 def event_exchange @event_exchange ||= event_channel.fanout [:event_exchange] end |
#listen_for_resend_requests ⇒ Object
35 36 37 38 39 |
# File 'lib/active_event/event_server.rb', line 35 def listen_for_resend_requests resend_request_queue.subscribe do |delivery_info, properties, id| resend_request_received id end end |
#resend_events_after(id) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_event/event_server.rb', line 24 def resend_events_after(id) if @replay_server_thread.nil? || !@replay_server_thread.alive? @replay_server_thread = Thread.new do Thread.current.priority = -10 ReplayServer.start , id end else ReplayServer.update id end end |
#resend_request_exchange ⇒ Object
58 59 60 |
# File 'lib/active_event/event_server.rb', line 58 def resend_request_exchange @resend_request_exchange ||= event_channel.direct "resend_request_#{[:event_exchange]}" end |
#resend_request_queue ⇒ Object
62 63 64 |
# File 'lib/active_event/event_server.rb', line 62 def resend_request_queue @resend_request_queue ||= event_channel.queue('', auto_delete: true).bind(resend_request_exchange, routing_key: 'resend_request') end |
#resend_request_received(id) ⇒ Object
41 42 43 44 |
# File 'lib/active_event/event_server.rb', line 41 def resend_request_received (id) puts "received resend request with id #{id}" resend_events_after id.to_i end |
#start ⇒ Object
19 20 21 22 |
# File 'lib/active_event/event_server.rb', line 19 def start event_connection.start listen_for_resend_requests end |