goagent is a library to help building task systems in golang. goagent currently supports rabbitmq and redis as MQ brokers.
+---------+ +-------+------------+
| Agent.1 | <--------> | | |
+---------+ | g | RabbitMQ |
| o | Broker | Request
+---------+ | a | | <---- TaskRequestTopic ---- +------------------+
| Agent.2 | <--------> | g |------------+ | Task distributor |
+---------+ | e | | ----- TaskResultTopic ---> +------------------+
| n | Redis | Result
+---------+ | t | Broker |
| Agent.3 | <--------> | | |
+---------+ +-------+------------+
-
Agent ID is an idenfitication for each task agent.
-
Each task agent will subscribe the given task request topic. The task distributor will send task request to given task request topic for new task.
Task request topicis not required to be unique accross different agents. Two or more agents can handle the same task request if you need to. -
When the agent finishes processing the request, result is send back the task distributor through
Task result topic. The result should be in form of Result. -
The parallel parameter is used to control how many tasks could be handled simultaneously. The upper boud is the number of cpus, the lower bound is 1. If parallel is set to 1, then only one task could be handled at a time, if the previous task not done, the succceeding task will be block until the previous one finished.
-
Task timeout is used to control how long the handler function is allowed to handle the request. If the task handle function exceed the timeout limit,
ErrTimeoutis raised. -
The request should conform to interface Request, which implement the
GetIDmethod.GetIDshould return the id for the request. -
The task handler should return Response as task response. If
Successfield istrue, means the task handler have process request successfully, otherwise,Errorfield will contain the error rease for the failure.Resultfield is the detail of the process result.
- For rabbitmq broker, please refer to example_rabbitmq_test.go
- For redis broker, please refer to example_redis_test.go