Agent framework designed for testing ZeroMQ Applications
The agent types correspond to underlying ZMQ Socket type under test
- Connects or Binds to local address
- Includes message caching for inspection
- Connects or Binds to local address
- Publishes
- Connects or Binds to local address
- Publishes request, returns response
- Connects or Binds to local address
- Listens for request, sends response
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
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
Grab the agent by the name given in the config file
my_agent = AgentZeroMQ.agents_hash[:my_sub_agent]
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
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"]
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"]
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.
There is some support for cucumber. See features/ for example usage.