Class: Nsq::Message

Inherits:
Frame
  • Object
show all
Defined in:
lib/nsq/frames/message.rb

Instance Attribute Summary collapse

Attributes inherited from Frame

#connection, #data

Instance Method Summary collapse

Methods included from AttributeLogger

included

Constructor Details

#initialize(data, connection) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
# File 'lib/nsq/frames/message.rb', line 10

def initialize(data, connection)
  super
  @timestamp_in_nanoseconds, @attempts, @id, @body = @data.unpack('Q>S>a16a*')
  @body.force_encoding('UTF-8')
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



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

def attempts
  @attempts
end

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/nsq/frames/message.rb', line 8

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/nsq/frames/message.rb', line 7

def id
  @id
end

Instance Method Details

#finishObject



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

def finish
  connection.fin(id)
end

#requeue(timeout = 0) ⇒ Object



20
21
22
# File 'lib/nsq/frames/message.rb', line 20

def requeue(timeout = 0)
  connection.req(id, timeout)
end

#timestampObject



28
29
30
# File 'lib/nsq/frames/message.rb', line 28

def timestamp
  Time.at(@timestamp_in_nanoseconds / 1_000_000_000.0)
end

#touchObject



24
25
26
# File 'lib/nsq/frames/message.rb', line 24

def touch
  connection.touch(id)
end