Class: Cpi::EventConnector
- Inherits:
-
Object
- Object
- Cpi::EventConnector
- Defined in:
- lib/cpi/event_connector.rb
Class Attribute Summary collapse
-
.connection_params ⇒ Object
Returns the value of attribute connection_params.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .configure(params, logger = nil) ⇒ Object
-
.send_event(xml, options = nil) ⇒ Object
This method expects a routing header to be present in the xml document.
- .test_connectivity ⇒ Object
- .transmit(event_type, tenant_uid, content, options = nil) ⇒ Object
Class Attribute Details
.connection_params ⇒ Object
Returns the value of attribute connection_params.
8 9 10 |
# File 'lib/cpi/event_connector.rb', line 8 def connection_params @connection_params end |
.logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/cpi/event_connector.rb', line 9 def logger @logger end |
Class Method Details
.configure(params, logger = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/cpi/event_connector.rb', line 14 def self.configure(params, logger=nil) @logger = logger || Logger.new("/dev/null") @logger.info "CPI Event Connector initialized" @enabled = !!params.delete(:enabled) @logger.info "CPI Event Connector is " + (@enabled ? "" : "not ") + "enabled" self.connection_params = params end |
.send_event(xml, options = nil) ⇒ Object
This method expects a routing header to be present in the xml document
<cpi_event>
<header>
<event_uid>unique_id</event_uid> - optional
<event_type>type</event_type>
<source_tenant_uid>tenant_uid</source_tenant_uid>
</header>
<content>some content</content>
</cpi_event>
46 47 48 49 50 51 |
# File 'lib/cpi/event_connector.rb', line 46 def self.send_event(xml, =nil) ||= {} d = Event.new(xml) transmit(d.event_type, d.source_tenant_uid, xml, {:queue => .delete(:queue), :uid => d.event_uid}) end |
.test_connectivity ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/cpi/event_connector.rb', line 53 def self.test_connectivity if !@enabled return 'Event Connector is not enabled.' end self.connector.test_connectivity end |
.transmit(event_type, tenant_uid, content, options = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cpi/event_connector.rb', line 22 def self.transmit(event_type, tenant_uid, content, =nil) ||= {} if !@enabled @logger.debug "Aborting transmit because CPI Event Connector not enabled" return end raise ArgumentError, "Tenant UID must be specified" if tenant_uid.blank? event_json = Generator.create_event(event_type, tenant_uid, content, .delete(:uid)) @logger.debug "Transmitting message '#{event_json}'" self.connector.transmit(event_json, ) @logger.debug "Transmission complete" end |