Class: RServiceBus2::Message

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

Overview

This is the top level message that is passed around the bus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, return_address, correlation_id = nil) ⇒ Message

Constructor

Parameters:

  • msg (Object)

    The msg to be sent

  • returnAddress (Object)

    A queue to which the destination message handler can send replies



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rservicebus2/message.rb', line 17

def initialize(msg, return_address, correlation_id = nil)
  if RServiceBus2.check_environment_variable('RSBMSG_COMPRESS')
    @compressed = true
    @_msg = Zlib::Deflate.deflate(YAML.dump(msg))
  else
    @compressed = false
    @_msg = YAML.dump(msg)
  end

  @correlation_id = correlation_id
  @return_address = return_address

  @createdat = DateTime.now

  @msg_id = UUIDTools::UUID.random_create
  @error_list = []
end

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



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

def correlation_id
  @correlation_id
end

#error_listObject (readonly)

Returns the value of attribute error_list.



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

def error_list
  @error_list
end

#last_error_source_queueObject (readonly)

Returns the value of attribute last_error_source_queue.



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

def last_error_source_queue
  @last_error_source_queue
end

#last_error_stringObject (readonly)

Returns the value of attribute last_error_string.



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

def last_error_string
  @last_error_string
end

#msg_idObject (readonly)

Returns the value of attribute msg_id.



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

def msg_id
  @msg_id
end

#remote_host_nameObject (readonly)

Returns the value of attribute remote_host_name.



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

def remote_host_name
  @remote_host_name
end

#remote_queue_nameObject (readonly)

Returns the value of attribute remote_queue_name.



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

def remote_queue_name
  @remote_queue_name
end

#return_addressObject (readonly)

Returns the value of attribute return_address.



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

def return_address
  @return_address
end

#sendatObject (readonly)

Returns the value of attribute sendat.



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

def sendat
  @sendat
end

Instance Method Details

#add_error_msg(source_queue, error_string) ⇒ Object

If an error occurs while processing the message, this method allows details of the error to held next to the msg.

Error(s) are held in an array, which allows current error information to be held, while still retaining historical error messages.

Parameters:

  • source_queue (Object)

    The name of the queue to which the msg should be returned

  • error_string (Object)

    A readible version of what occured



43
44
45
46
47
48
# File 'lib/rservicebus2/message.rb', line 43

def add_error_msg(source_queue, error_string)
  @last_error_source_queue = source_queue
  @last_error_string = error_string

  @error_list << RServiceBus2::ErrorMessage.new(source_queue, error_string)
end

#msgObject

Returns The msg to be sent.

Returns:

  • (Object)

    The msg to be sent



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rservicebus2/message.rb', line 63

def msg
  if @compressed == true
    return YAML.load(Zlib::Inflate.inflate(@_msg))
  else
    return YAML.load( @_msg )
  end
rescue ArgumentError => e
  raise e if e.message.index('undefined class/module ').nil?

  puts e.message
  msg_name = e.message.sub('undefined class/module ', '')

  raise ClassNotFoundForMsg, msg_name
end

#send_at(timestamp) ⇒ Object



58
59
60
# File 'lib/rservicebus2/message.rb', line 58

def send_at(timestamp)
  @send_at = timestamp
end

#set_remote_host_name(host_name) ⇒ Object



50
51
52
# File 'lib/rservicebus2/message.rb', line 50

def set_remote_host_name(host_name)
  @remote_host_name = host_name
end

#set_remote_queue_name(queue_name) ⇒ Object



54
55
56
# File 'lib/rservicebus2/message.rb', line 54

def set_remote_queue_name(queue_name)
  @remote_queue_name = queue_name
end