Agent Bus - jmadison222/knowledge GitHub Wiki

| Home |


Table of Contents


System Requirements

  • Linux is the operating system.

  • Python is the programming language.

  • Invocation is from the command line.

  • All communication among AGENTS, PRODUCERS, and CONSUMERS is over TCP/IP.

  • The TCP/IP ports used start at 30000 and may range up to 31000.


Message Structure

  • The PRODUCER and CONSUMER will pass a MESSAGE.

  • 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 "add", "multiply", or "answer".


Message Bus

  • The purpose of the MESSAGE_BUS is to facilitate the passing of MESSAGES among AGENTS, PRODUCERS, and CONSUMERS.

  • 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.

  • The MESSAGE_BUS puts all MESSAGES on the FIFO queue when the AGENT_TYPE in the message is "consumer".

  • The MESSAGE_BUS listens on TCP/IP for AGENTS, PRODUCERS, or CONSUMERS to send MESSAGES or request MESSAGES.

  • The MESSAGE_BUS runs indefinitely until a USER sends Control-C.


Producer

  • 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.


Consumer

  • 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.


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.


1. Notes

Ignore everything in this section and the remainder of the page. These are notes not requirements.

for i in {1..1000}; do python consumer.py add $(RANDOM % 10) + 1 $(RANDOM % 10) + 1 ; done

⚠️ **GitHub.com Fallback** ⚠️