Package: miniagent
MiniagentMiniagent is a multi-adaptable and lightweight server framework based onFlask.InstallingInstall and update usingpip:$ pip install -U miniagentAdvised Virtual Environment InstallVirtual env is highly advisable because the more projects you have, the more likely it is that you will be working with different versions of Python itself, or at least different versions of Python libraries.$ pip install virtualenvNext create a virtualenv:$ virtualenv venv
New python executable in venv/bin/python
Installing distribute............done.
$ . venv/bin/activate
(venv)$Now install miniagent on the virtual env, it will install all the dependencies and these will be isolated from your system’s python packages(venv)$ pip install miniagentConfiguration VariablesConfiguration variables defined in the config.py fileVariableTypeDescriptionDefaultDEBUGboolDebug mode y/nTrueAGENT_NAMEstrIt is used to identify a specific service.main .py file nameAGENT_ROLESlistorstrREST api, message receiver, and scheduler job resources defined in miniagent can grant authority only to specific roles. This variable is useful when implementing services of multiple roles with one application.ex:AGENT_ROLES = "customer,tester"COMMAND_RECEIVER_ENABLEDboolIt indicates whether to use Command Receiver or not.FalseCOMMANDER_SERVER_URLstrURL to be polled by Command ReceiverCOMMANDER_RESPONSE_CONVERTERstrPath of function that processes the response received by Command Receiver so that Executor can process it.  If it is not defined, the response is sent to Executor without being processed.ex:COMMANDER_RESPONSE_CONVERTER = "example.etc.command_converter"MESSAGE_RECEIVER_ENABLEDboolIt indicates whether to use Message Receiver(Kafka consumer) or not.FalseKAFKA_BOOTSTRAP_SERVERSlist(str)A list of kafka bootstrap servers to be called by Message ReceiverEXECUTERS_BY_TOPIClist(dir)Kafka topics to be polled by Message Receiver and Executors to handle processing for each topic.ex:EXECUTERS_BY_TOPIC =[{"topic":"TEST_TOPIC",    "executer":"example.executer.say_hello.PrintParam", "agent_roles":["tester","admin"]}]SQLALCHEMY_DATABASE_URIstrURI of dedicated database of the service"sqlite:///" + os.path.join(base_dir, "app.db")CUSTOM_MODELS_PATHstrPath of data models added by the applicationex:CUSTOM_MODELS_PATH = "example.model"CUSTOM_APIS_PATHstrPath of REST APIs added by the applicationex:CUSTOM_APIS_PATH = "example.api"TIMEZONEstrTimezone to be used in miniagentex:TIMEZONE = "Asia/Seoul"SCHEDULER_API_ENABLEDboolIt indicates whether to open REST APIs of Job Scheduler or not.FalseEXIT_AFTER_JOBSboolIt indicates whether to terminate the service when all jobs scheduled in Job Scheduler are finished.FalseSCHEDULED_JOBSlist(dir)List of jobs to be scheduled in Job SchedulerDEFAULT_ADAPTEESdirIf the application uses a 3rd party solution, register the 3rd party solution library as an adaptee and develop an adapter so that the executor can use it. That variable defines the mapping of adapters and adaptees.ZIPKIN_ADDRESStuple(str,int)Zipkin server address.ex:ZIPKIN_ADDRESS = ("localhost",9411)Sample code downloadCreate an sample project after installing miniagent$ mini-project tanminkwan/banking-poc /Then the source files are downloaded from Github on the current directory. The following is the directory tree.├── banking  
│   ├── __init__.py  
│   ├── api  
│   │   ├── __init__.py  
│   │   ├── bapis.py  
│   ├── dbquery  
│   │   └── queries.py  
│   ├── executer  
│   │   ├── __init__.py  
│   │   ├── deposit.py  
│   │   ├── event.py  
│   │   └── raffle.py  
│   └── model  
│       ├── __init__.py  
│       └── models.py  
├── app.py  
├── config.py  
├── bonnie.py  
├── clyde.py  
├── john_dillinger.py  
├── deposit.py  
├── event.py  
└── raffle.pyRun Kafka, Opensearch and Zipkin servicesRun Kafka, Opensearch and Zipkin and register the endpoints of them in config.py.ZIPKIN_DOMAIN_NAME = 'localhost'
ZIPKIN_PORT =  '9411'
KAFKA_BOOTSTRAP_SERVERS = 'localhost:9092'
ELASTIC_SEARCH_DOMAIN_NAME = 'localhost'
ELASTIC_SEARCH_PORT = '9200'Run the six applicationsRun the five applications as below.$ nohup python raffle.py &
$ nohup python deposit.py &
$ nohup python event.py &
$ nohup python clyde.py &
$ nohup python bonnie.py &
$ nohup python john_dillinger.py &Open Zipkin web site and check the transactionsClyde and Bonnie send requests to Deposit and Event every 30 seconds.Deposit produces messages and Raffle consumes the messages via Kafka.Event calls Raffle whenever it receive a request from Clyde and Bonnie.John Dillinger requests deposit amount by account from Event every 30 seconds.Event retrieves this information from Opensearch and provides it to John Dillinger.You can see all of them on the Zipkin dashboard.(Maybehttp://localhost:9411)