Class: RabbitRPC::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rabbit_rpc/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, *args) ⇒ Message

Returns a new instance of Message.



8
9
10
11
# File 'lib/rabbit_rpc/message.rb', line 8

def initialize(method_name, *args)
  @method_name = method_name
  @args        = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



6
7
8
# File 'lib/rabbit_rpc/message.rb', line 6

def args
  @args
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



6
7
8
# File 'lib/rabbit_rpc/message.rb', line 6

def method_name
  @method_name
end

Class Method Details

.generate_idObject



29
30
31
# File 'lib/rabbit_rpc/message.rb', line 29

def self.generate_id
  SecureRandom.uuid
end

.unpack(message) ⇒ Object

Unpacks a serialized message to a hash containing the method and its args. This method needs to be modified if a serializer other than MessagePack is to be used.

Returns a Hash



25
26
27
# File 'lib/rabbit_rpc/message.rb', line 25

def self.unpack(message)
  MessagePack.unpack message
end

Instance Method Details

#packObject

Squeezes and serializes the RPC method name and arguments

Returns the packed and serialized string



16
17
18
# File 'lib/rabbit_rpc/message.rb', line 16

def pack
  serialize(method: @method_name, args: @args)
end