Skip to content

Agent framework designed for testing ZeroMQ Applications

License

Notifications You must be signed in to change notification settings

bhaan/agent_zeromq

 
 

Repository files navigation

agent_zeromq

Agent framework designed for testing ZeroMQ Applications

Agent Types

The agent types correspond to underlying ZMQ Socket type under test

ZMQ_SUB

  • Connects or Binds to local address
  • Includes message caching for inspection

ZMQ_PUB

  • Connects or Binds to local address
  • Publishes

ZMQ_REQ

  • Connects or Binds to local address
  • Publishes request, returns response

ZMQ_REP

  • Connects or Binds to local address
  • Listens for request, sends response

Usage

Configuration

Inside of your project, declare your agents inside of config/zmq_agents.rb like this:

require 'agent_zeromq'

AgentZeroMQ.define_ZMQ_SUB :my_sub_agent do |a|
  a.socket_opts << {ZMQ::SUBSCRIBE=>'com.connamara.BODPosition'}
  a.end_point_type=:bind
  a.end_point='tcp://*:5556'
end

AgentZeroMQ.define_ZMQ_PUB :my_pub_agent do |a|
  a.end_point_type=:connect
  a.end_point='tcp://127.0.0.1:5558'
end

AgentZeroMQ.define_ZMQ_REQ :my_req_agent do |a|
  a.end_point_type=:connect
  a.end_point='tcp://127.0.0.1:5552'
end

AgentZeroMQ.define_ZMQ_REP :my_rep_agent do |a|
  a.reply = Proc.new {|msg| "ok"}
  a.end_point_type=:bind
  a.end_point='tcp://*:5552'
end

Starting, Stopping and Resetting

require 'agent_zeromq'
AgentZeroMQ.start
at_exit { AgentZeroMQ.stop }

You may want to reset the agent states between tests without stopping and starting. This may be done with AgentZeroMQ.reset

Getting your agent

Grab the agent by the name given in the config file

my_agent = AgentZeroMQ.agents_hash[:my_sub_agent]  

Agent Interfaces

ZMQ_SUB

This agent provides a message cache

all_messages_received = my_sub_agent.messages_received

# returns and removes the last message received from the cache
last_message_received = my_sub_agent.pop

On reset, the sub agent cache is cleared

ZMQ_PUB

The publish method takes a single message of one or more parts

my_pub_agent.publish "single part message"
my_pub_agent.publish ["part 1", "part 2"]

ZMQ_REQ

The publish method takes a single message of one or more parts. The agent blocks until a response is received and returned as an array of message parts

response = my_req_agent.publish "single part message"
response = my_pub_agent.publish ["part 1", "part 2"]

ZMQ_REP

Like the ZMQ_SUB agent, ZMQ_REP provides a message cache

all_messages_received = my_rep_agent.messages_received

# returns and removes the last message received from the cache
last_message_received = my_rep_agent.pop

When receiving requests, the agent will reply with the output of the reply Proc. The return value of this proc may be in the form of a multi-part message.

Cucumber

There is some support for cucumber. See features/ for example usage.

About

Agent framework designed for testing ZeroMQ Applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%