Class: RServiceBus::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/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, returnAddress, correlationId = nil) ⇒ Message

Constructor

Parameters:

  • msg (Object)

    The msg to be sent

  • returnAddress (Object)

    A queue to which the destination message handler can send replies



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

def initialize( msg, returnAddress, correlationId=nil )
    unless RServiceBus.checkEnvironmentVariable('RSBMSG_COMPRESS') then
      @compressed = false
      @_msg=YAML::dump(msg)
    else
      @compressed = true
      @_msg=Zlib::Deflate.deflate(YAML::dump(msg))
    end

    @correlationId = correlationId
    @returnAddress=returnAddress

    @createdAt = DateTime.now

    @msgId=UUIDTools::UUID.random_create
    @errorList = Array.new
end

Instance Attribute Details

#correlationIdObject (readonly)

Returns the value of attribute correlationId.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def correlationId
  @correlationId
end

#lastErrorSourceQueueObject (readonly)

Returns the value of attribute lastErrorSourceQueue.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def lastErrorSourceQueue
  @lastErrorSourceQueue
end

#lastErrorStringObject (readonly)

Returns the value of attribute lastErrorString.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def lastErrorString
  @lastErrorString
end

#msgIdObject (readonly)

Returns the value of attribute msgId.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def msgId
  @msgId
end

#remoteHostNameObject (readonly)

Returns the value of attribute remoteHostName.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def remoteHostName
  @remoteHostName
end

#remoteQueueNameObject (readonly)

Returns the value of attribute remoteQueueName.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def remoteQueueName
  @remoteQueueName
end

#returnAddressObject (readonly)

Returns the value of attribute returnAddress.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def returnAddress
  @returnAddress
end

#sendAt(timestamp) ⇒ Object (readonly)

Returns the value of attribute sendAt.



10
11
12
# File 'lib/rservicebus/Message.rb', line 10

def sendAt
  @sendAt
end

Instance Method Details

#addErrorMsg(sourceQueue, errorString) ⇒ 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:

  • sourceQueue (Object)

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

  • errorString (Object)

    A readible version of what occured



42
43
44
45
46
47
# File 'lib/rservicebus/Message.rb', line 42

def addErrorMsg( sourceQueue, errorString )
    @lastErrorSourceQueue = sourceQueue
    @lastErrorString = errorString

    @errorList << RServiceBus::ErrorMessage.new( sourceQueue, errorString )
end

#msgObject

Returns The msg to be sent.

Returns:

  • (Object)

    The msg to be sent



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rservicebus/Message.rb', line 62

def msg
    if @compressed == true then
        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.new( msg_name )
end

#setRemoteHostName(hostName) ⇒ Object



49
50
51
# File 'lib/rservicebus/Message.rb', line 49

def setRemoteHostName( hostName )
    @remoteHostName = hostName
end

#setRemoteQueueName(queueName) ⇒ Object



53
54
55
# File 'lib/rservicebus/Message.rb', line 53

def setRemoteQueueName( queueName )
    @remoteQueueName = queueName
end