Class: RServiceBus::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus/Agent.rb

Overview

A means for a stand-alone process to interact with the bus, without being a full rservicebus application

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



19
20
21
# File 'lib/rservicebus/Agent.rb', line 19

def initialize
    @mq = MQ.get
end

Instance Method Details

#checkForReply(queueName) ⇒ Object

Gives an agent the means to receive a reply

Parameters:

  • queueName (String)

    the name of the queue to monitor for messages



51
52
53
54
55
56
57
# File 'lib/rservicebus/Agent.rb', line 51

def checkForReply( queueName )
    @mq.subscribe( queueName )
    body = @mq.pop
    @msg = YAML::load(body)
    @mq.ack
    return @msg.msg
end

#getAgent(uri) ⇒ Object



12
13
14
15
16
17
# File 'lib/rservicebus/Agent.rb', line 12

def getAgent( uri )
    ENV['RSBMQ'] = uri.to_s

    RServiceBus.rlog '*** Agent.getAgent has been deprecated. Set the environment variable, RSBMQ, and simply create the class'
	    return Agent.new
end

#sendMsg(messageObj, queueName, returnAddress = nil) ⇒ Object

Put a msg on the bus

Parameters:

  • messageObj (Object)

    The msg to be sent

  • queueName (String)

    the name of the queue to be send the msg to

  • returnAddress (String) (defaults to: nil)

    the name of a queue to send replies to

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rservicebus/Agent.rb', line 28

def sendMsg(messageObj, queueName, returnAddress=nil)
    raise QueueNotFoundForMsg.new( messageObj.class.name ) if queueName.nil?

    msg = RServiceBus::Message.new( messageObj, returnAddress )

    
    if queueName.index('@').nil? then
        q = queueName
        else
        parts = queueName.split('@')
        msg.setRemoteQueueName( parts[0] )
        msg.setRemoteHostName( parts[1] )
        q = 'transport-out'
    end
    
    serialized_object = YAML::dump(msg)
    
    @mq.send( q, serialized_object )
end