Class: Msgr::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, delivery_info, metadata, payload, route) ⇒ Message

Returns a new instance of Message


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/msgr/message.rb', line 7

def initialize(channel, delivery_info, , payload, route)
  @channel       = channel
  @delivery_info = delivery_info
  @metadata      = 
  @payload       = payload
  @route         = route

  # rubocop:disable Style/GuardClause
  if content_type == 'application/json'
    @payload = MultiJson.load(payload)
    @payload.symbolize_keys! if @payload.respond_to? :symbolize_keys!
  end
end

Instance Attribute Details

#delivery_infoObject (readonly)

Returns the value of attribute delivery_info


5
6
7
# File 'lib/msgr/message.rb', line 5

def delivery_info
  @delivery_info
end

#metadataObject (readonly)

Returns the value of attribute metadata


5
6
7
# File 'lib/msgr/message.rb', line 5

def 
  @metadata
end

#payloadObject (readonly)

Returns the value of attribute payload


5
6
7
# File 'lib/msgr/message.rb', line 5

def payload
  @payload
end

#routeObject (readonly)

Returns the value of attribute route


5
6
7
# File 'lib/msgr/message.rb', line 5

def route
  @route
end

Instance Method Details

#ackObject

Send message acknowledge to broker unless message is already acknowledged.


39
40
41
42
43
44
# File 'lib/msgr/message.rb', line 39

def ack
  return if acked?

  @acked = true
  @channel.ack delivery_info.delivery_tag
end

#acked?Boolean

Check if message is already acknowledged.

Returns:

  • (Boolean)

    True if message is acknowledged, false otherwise.


30
31
32
# File 'lib/msgr/message.rb', line 30

def acked?
  @acked ? true : false
end

#content_typeObject


21
22
23
# File 'lib/msgr/message.rb', line 21

def content_type
  @metadata.content_type
end

#nackObject

Send negative message acknowledge to broker unless message is already acknowledged.


51
52
53
54
55
56
# File 'lib/msgr/message.rb', line 51

def nack
  return if acked?

  @acked = true
  @channel.nack delivery_info.delivery_tag
end