Class: RServiceBus2::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/rservicebus2/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.



18
19
20
# File 'lib/rservicebus2/agent.rb', line 18

def initialize
  @mq = MQ.get
end

Instance Method Details

#check_for_reply(queue_name) ⇒ Object

Gives an agent the means to receive a reply

Parameters:

  • queueName (String)

    the name of the queue to monitor for messages



50
51
52
53
54
55
56
# File 'lib/rservicebus2/agent.rb', line 50

def check_for_reply(queue_name)
  @mq.subscribe(queue_name)
  body = @mq.pop
  @msg = RServiceBus2.safe_load(body)
  @mq.ack
  @msg.msg
end

#get_agent(uri) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/rservicebus2/agent.rb', line 10

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

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

#send_msg(message_obj, queue_name, return_address = nil) ⇒ Object

Put a msg on the bus

rubocop:disable Metrics/MethodLength

Parameters:

  • messageObj (Object)

    The msg to be sent

  • queueName (String)

    the name of the queue to be send the msg to

  • returnAddress (String)

    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
# File 'lib/rservicebus2/agent.rb', line 28

def send_msg(message_obj, queue_name, return_address = nil)
  raise QueueNotFoundForMsg, message_obj.class.name if queue_name.nil?

  msg = RServiceBus2::Message.new(message_obj, return_address)
  if queue_name.index('@').nil?
    q = queue_name
  else
    parts = queueName.split('@')
    msg.remote_queue_name = parts[0]
    msg.remote_host_name = parts[1]
    q = 'transport-out'
  end

  serialized_object = YAML.dump(msg)

  @mq.send(q, serialized_object)
end