class PubSubModelSync::Payload
Attributes
data[R]
headers[R]
info[R]
Public Class Methods
from_payload_data(data)
click to toggle source
convert payload data into Payload
@param data [Hash]: payload data (:data, :info, :headers)
# File lib/pub_sub_model_sync/payload.rb, line 80 def self.from_payload_data(data) data = data.symbolize_keys new(data[:data], data[:info] || data[:attributes], data[:headers]) end
new(data, info, headers = {})
click to toggle source
@param data (Hash: { any value }): @param info (Hash):
klass: (String, required) Notification class name action: (Symbol, required) Notification action name mode: (:model|:klass, default :model): :model for instance and :klass for class notifications
@param headers (Hash):
key (String): identifier of the payload, default: <klass/action>: when class message <klass/action/model.id>: when model message ordering_key (String): messages with the same key are processed in the same order they were delivered, default: <klass>: when class message <klass/id>: when model message topic_name (String|Array<String>): Specific topic name to be used when delivering the message (default first topic) forced_ordering_key (String, optional): Will force to use this value as the ordering_key, even withing transactions. Default nil.
# File lib/pub_sub_model_sync/payload.rb, line 25 def initialize(data, info, headers = {}) @data = data.deep_symbolize_keys @info = info.deep_symbolize_keys @headers = headers.deep_symbolize_keys build_headers validate! end
Public Instance Methods
action()
click to toggle source
# File lib/pub_sub_model_sync/payload.rb, line 42 def action info[:action].to_sym end
klass()
click to toggle source
# File lib/pub_sub_model_sync/payload.rb, line 38 def klass info[:klass].to_s end
mode()
click to toggle source
# File lib/pub_sub_model_sync/payload.rb, line 46 def mode (info[:mode] || :model).to_sym end
process()
click to toggle source
Process payload data
(If error will call on_error_processing callback)
# File lib/pub_sub_model_sync/payload.rb, line 59 def process publisher = PubSubModelSync::MessageProcessor.new(self) publisher.process end
process!()
click to toggle source
Process payload data
(If error will raise exception and wont call on_error_processing callback)
# File lib/pub_sub_model_sync/payload.rb, line 52 def process! publisher = PubSubModelSync::MessageProcessor.new(self) publisher.process! end
publish()
click to toggle source
Publish payload to pubsub
(If error will call on_error_publish callback)
# File lib/pub_sub_model_sync/payload.rb, line 73 def publish klass = PubSubModelSync::MessagePublisher klass.publish(self) end
publish!()
click to toggle source
Publish payload to pubsub
(If error will raise exception and wont call on_error_publish callback)
# File lib/pub_sub_model_sync/payload.rb, line 66 def publish! klass = PubSubModelSync::MessagePublisher klass.publish!(self) end
to_h()
click to toggle source
@return Hash: payload data
# File lib/pub_sub_model_sync/payload.rb, line 34 def to_h { data: data.clone, info: info.clone, headers: headers.clone } end
Private Instance Methods
build_headers()
click to toggle source
# File lib/pub_sub_model_sync/payload.rb, line 87 def build_headers headers[:app_key] ||= PubSubModelSync::Config.subscription_key headers[:key] ||= [klass, action].join('/') headers[:ordering_key] ||= klass headers[:uuid] ||= SecureRandom.uuid end
validate!()
click to toggle source
# File lib/pub_sub_model_sync/payload.rb, line 94 def validate! raise MissingInfo if !info[:klass] || !info[:action] end