Class: EventHub::ActorPublisher
- Inherits:
-
Object
- Object
- EventHub::ActorPublisher
- Includes:
- Celluloid, Helper
- Defined in:
- lib/eventhub/actor_publisher.rb
Overview
Publisher class
Instance Method Summary collapse
- #cleanup ⇒ Object
-
#initialize ⇒ ActorPublisher
constructor
A new instance of ActorPublisher.
- #publish(args = {}) ⇒ Object
Methods included from Helper
#create_bunny_connection, #get_name_from_class, #now_stamp, #stringify_keys
Constructor Details
#initialize ⇒ ActorPublisher
10 11 12 13 |
# File 'lib/eventhub/actor_publisher.rb', line 10 def initialize EventHub.logger.info("Publisher is starting...") @connection = nil end |
Instance Method Details
#cleanup ⇒ Object
46 47 48 49 |
# File 'lib/eventhub/actor_publisher.rb', line 46 def cleanup EventHub.logger.info("Publisher is cleaning up...") @connection&.close end |
#publish(args = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/eventhub/actor_publisher.rb', line 15 def publish(args = {}) # keep connection once established unless @connection @connection = create_bunny_connection @connection.start end = args[:message] return if .nil? exchange_name = args[:exchange_name] || EH_X_INBOUND channel = @connection.create_channel channel.confirm_select exchange = channel.direct(exchange_name, durable: true) = {persistent: true} correlation_id = args[:correlation_id] || CorrelationId.current [:correlation_id] = correlation_id if correlation_id exchange.publish(, ) success = channel.wait_for_confirms unless success raise "Published message from Listener actor " \ "has not been confirmed by the server" end ensure channel&.close end |