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

rubocop:disable Metrics/MethodLength

Parameters:

  • msg (Object)

    The msg to be sent

  • returnAddress (Object)

    A queue to which the destination message handler can send replies



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rservicebus2/message.rb', line 22

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 = Time.now

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

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def correlation_id
  @correlation_id
end

#error_listObject (readonly)

Returns the value of attribute error_list.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def error_list
  @error_list
end

#last_error_source_queueObject (readonly)

Returns the value of attribute last_error_source_queue.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def last_error_source_queue
  @last_error_source_queue
end

#last_error_stringObject (readonly)

Returns the value of attribute last_error_string.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def last_error_string
  @last_error_string
end

#msg_idObject (readonly)

Returns the value of attribute msg_id.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def msg_id
  @msg_id
end

#remote_host_nameObject

Returns the value of attribute remote_host_name.



14
15
16
# File 'lib/rservicebus2/message.rb', line 14

def remote_host_name
  @remote_host_name
end

#remote_queue_nameObject

Returns the value of attribute remote_queue_name.



14
15
16
# File 'lib/rservicebus2/message.rb', line 14

def remote_queue_name
  @remote_queue_name
end

#return_addressObject (readonly)

Returns the value of attribute return_address.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

def return_address
  @return_address
end

#send_atObject

Returns the value of attribute send_at.



14
15
16
# File 'lib/rservicebus2/message.rb', line 14

def send_at
  @send_at
end

#sendatObject (readonly)

Returns the value of attribute sendat.



10
11
12
# File 'lib/rservicebus2/message.rb', line 10

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



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

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



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rservicebus2/message.rb', line 57

def msg
  return RServiceBus2.safe_load(Zlib::Inflate.inflate(@_msg)) if @compressed == true

  RServiceBus2.safe_load(@_msg)
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