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.



16
17
18
# File 'lib/rservicebus2/agent.rb', line 16

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



47
48
49
50
51
52
53
# File 'lib/rservicebus2/agent.rb', line 47

def check_for_reply(queue_name)
  @mq.subscribe(queue_name)
  body = @mq.pop
  @msg = YAML.load(body)
  @mq.ack
  @msg.msg
end

#get_agent(uri) ⇒ Object



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

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/AbcSize,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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rservicebus2/agent.rb', line 26

def send_msg(message_obj, queue_name, return_address = nil)
  fail 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.set_remote_queue_name(parts[0])
    msg.set_remote_host_name(parts[1])
    q = 'transport-out'
  end

  serialized_object = YAML.dump(msg)

  @mq.send(q, serialized_object)
end