class HonestPubsub::Message
Attributes
context[R]
payload[R]
pub[R]
ts[R]
version[R]
Public Class Methods
new()
click to toggle source
# File lib/honest_pubsub/message.rb, line 14 def initialize end
Public Instance Methods
parse(envelope)
click to toggle source
# File lib/honest_pubsub/message.rb, line 27 def parse(envelope) contents = Hashie::Mash.new(::JSON.parse(envelope)) @ts = contents[:ts] @pub = contents[:pub] # Version used for messaging can get updated if we need to add extra header information, and need # to move each section of the library separately. @version = contents[:v] @payload = contents[:payload] @context = ::HonestPubsub::Context.from_json(contents[:context]) to_hash end
serialize(context, routing_key, payload)
click to toggle source
Context
object should be passed into the call.
# File lib/honest_pubsub/message.rb, line 18 def serialize(context, routing_key, payload) @ts = Time.now.to_i @pub = "#{routing_key}:#{Socket.gethostname()}:#{Process::pid}" @version = @@message_version @payload = payload @context = context to_hash end
to_hash()
click to toggle source
# File lib/honest_pubsub/message.rb, line 39 def to_hash ::Hashie::Mash.new({ ts: @ts, pub: @pub, v: @@message_version, payload: @payload, context: @context.as_json }) end