Agent Bus - jmadison222/knowledge GitHub Wiki
| Home |
-
Linux is the operating system.
-
Python is the programming language.
-
Invocation is from the command line.
-
All communication among AGENTS and the MESSAGE_BUS is over TCP/IP.
-
The TCP/IP ports used start at 30000 and may range up to 31000.
-
An AGENT can pass a MESSAGE to the MESSAGE_BUS.
-
The format of the MESSAGE is JSON.
-
The MESSAGE contains the following fields:
-
AGENT_NAME - A string that uniquely identifies an AGENT.
-
AGENT_TYPE - A string that provides the type of AGENT.
-
OPERATION - A string that describes an ACTION performed by an AGENT.
-
OPERAND-1 - A number that participates in an OPERATION.
-
OPERAND-2 - A number that participates in an OPERATION.
-
ANSWER - A number that is produced from an OPERATION.
-
-
The AGENT_TYPE must have exactly one of the values "producer" or "consumer".
-
Any AGENT_TYPE that is not one of the allowed values must cause the process to terminate with a graceful message.
-
The OPERATIONS must have exactly one of the values "buy", "retrieve", or "sell".
-
The MESSAGE_BUS uses the design pattern of message passing using a bus architecture as commonly found in industry literature.
-
The purpose of the MESSAGE_BUS is to facilitate the passing of MESSAGES among AGENTS.
-
The invocation of the MESSAGE_BUS from the command line is done with "python bus.py"
-
The MESSAGE_BUS maintains a FIFO queue of messages.
-
Additions to the FIFO queue occur at the end of the queue only.
-
Removals from the FIFO queue occur at the front of the queue by default.
-
If a search is performed on the FIFO queue, a removal from the queue may occur for the message that was found in the search.
-
There is exactly one FIFO queue in the MESSAGE_BUS.
-
-
When inside the MESSAGE_BUS, a MESSAGE can take on the role of incoming MESSAGE, existing MESSAGE, or outgoing MESSAGE:
-
A MESSAGE is an incoming MESSAGE when it comes from an AGENT and is sent to the MESSAGE_BUS.
-
A MESSAGE is an existing MESSAGE when it is stored in the FIFO queue.
-
A MESSAGE becomes an outgoing MESSAGE when it has been removed from the FIFO queue and is being provided to an AGENT by the MESSAGE_BUS.
-
-
The MESSAGE_BUS listens on TCP/IP for AGENTS to provide incoming MESSAGES.
-
When an incoming MESSAGE has an AGENT_TYPE of "consumer" and an OPERATION of "buy", the MESSAGE_BUS takes the following actions:
-
Search from the front of the FIFO queue for the first existing message that matches the AGENT_NAME and OPERATION of the MESSAGE.
-
If the search finds an existing MESSAGE already on the FIFO queue, return it to the AGENT immediately and take no further action.
-
If the search does not find an existing MESSAGE already on the FIFO queue, place the incoming MESSAGE at the end of the FIFO queue.
-
-
When an incoming MESSAGE has an AGENT_TYPE of "producer" and an OPERATION of "retrieve", the MESSAGE_BUS takes the following actions:
-
If the FIFO queue is empty, return the MESSAGE back to the AGENT that made the request with no changes and skip the remaining steps.
-
Search from the front of the FIFO queue for the first existing MESSAGE that contains an OPERATION of "buy".
-
Remove the existing MESSAGE from the FIFO queue and provide it to the AGENT.
-
-
The MESSAGE_BUS runs indefinitely until a USER sends Control-C.
-
The invocation of the PRODUCER from the command line is done with "python producer.py"
-
The PRODUCER listens to the TCP/IP port.
-
The PRODUCER consumes a MESSAGE from the TCP/IP port.
-
The PRODUCER finds the OPERATION in the MESSAGE.
-
If the OPERATION is "multiply", the PRODUCER determines the product of OPERAND-1 and OPERAND-2 as the ANSWER
-
If the OPERATION is "add", the PRODUCER determines the sum of OPERAND-1 and OPERAND-2 as the ANSWER.
-
The PRODUCER builds a message to return in the manner prescribed next.
-
The PRODUCER puts all the original parts of the message it received so that the inputs are traceable.
-
The PRODUCER puts the ANSWER into the MESSAGE.
-
The PRODUCER shows the message on the command line so the USER can see the content.
-
The PRODUCER sends the MESSAGE over the TCP/IP port so the CONSUMER can receive it.
-
The PRODUCER waits for another message.
-
The PRODUCER runs indefinitely until a USER sends Control-C.
-
The invocation of the CONSUMER from the command line is done with "python consumer.py"
-
The command line takes the following positional parameters:
-
AGENT_NAME
-
OPERATION
-
OPERAND-1
-
OPERAND-2
-
-
If any parameters are not present, the user is given a help message on how to properly pass parameters.
-
The CONSUMER puts AGENT_NAME, OPERATION, OPERAND-1, OPERAND-2 into the MESSAGE format that is common to both the PRODUCER and CONSUMER.
-
The CONSUMER leaves the ANSWER blank.
-
The CONSUMER connects to TCP/IP port 30101 and sends the MESSAGE it has built.
-
The CONSUMER waits for a MESSAGE from the PRODUCER to come over the TCP/IP port.
-
When a return MESSAGE is received from the PRODUCER, the CONSUMER displays it on the screen for the USER.
-
The USER is a human at the Linux command line.
-
The USER will invoke the PRODUCER for it to run indefinitely.
-
The USER will invoke the CONSUMER each time it needs an ANSWER by running "python consumer.py" with parameters.
-
The USER may provide different parameters to the CONSUMER each time the CONSUMER is run.