Module: JsonapiPublisher
- Defined in:
- lib/jsonapi_publisher.rb,
lib/jsonapi_publisher/version.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
'0.2.8'.freeze
Class Attribute Summary collapse
-
.channel ⇒ Object
Returns the value of attribute channel.
- .configuration ⇒ Object
-
.connection ⇒ Object
Returns the value of attribute connection.
Class Method Summary collapse
- .configure {|configuration| ... } ⇒ Object
- .publish(routing_key, message = {}, event = '') ⇒ Object
- .reset_connection ⇒ Object
Class Attribute Details
.channel ⇒ Object
Returns the value of attribute channel.
14 15 16 |
# File 'lib/jsonapi_publisher.rb', line 14 def channel @channel end |
.configuration ⇒ Object
17 18 19 |
# File 'lib/jsonapi_publisher.rb', line 17 def self.configuration @configuration ||= Configuration.new end |
.connection ⇒ Object
Returns the value of attribute connection.
14 15 16 |
# File 'lib/jsonapi_publisher.rb', line 14 def connection @connection end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
21 22 23 |
# File 'lib/jsonapi_publisher.rb', line 21 def self.configure yield(configuration) end |
.publish(routing_key, message = {}, event = '') ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jsonapi_publisher.rb', line 25 def self.publish(routing_key, = {}, event = '') if .is_a?(ActiveRecord::Base) = ActiveModelSerializers::SerializableResource.new().as_json end = { event: event }.merge() if event.present? if configuration.qservice == 'rmq' x = channel.topic(ENV['EVENT_TOPIC'] || 'events') x.publish(.to_json, routing_key: routing_key) elsif configuration.qservice == 'sqs' = { routing_key: { string_value: routing_key, data_type: 'String' } } if configuration.avoid_send p; p "Requesting with queue_url: #{ENV['QUEUE_URL'] || channel.queue_url}, message_body: #{.to_json}, message_attributes: #{}" else connection.(queue_url: ENV['QUEUE_URL'] || channel.queue_url, message_body: .to_json, message_attributes: ) end end end |
.reset_connection ⇒ Object
65 66 67 68 69 |
# File 'lib/jsonapi_publisher.rb', line 65 def self.reset_connection self.connection = nil self.channel = nil configuration.qservice = nil end |