This repository serves two purposes:
-
it provides the base class for the default GridWorks actor using pika, the main python package for interacting with RabbitMQ
- install the
gwbasepackage via
$ pip install gridworks-base - install the
-
It provides scripts for runnig a local dev rabbit broker, which is the recommended way to develop.
All GridWorks repos require a running rabbitMQ dev broker running to pass tests or run dev simulations. Instructions for setting it up:
- Make sure you have docker installed
- Know whether your computer architecture is x86 or arm
- Start the dev broker in a docker container:
- x86 architecture:
./x86.sh - arm architecture:
./arm.sh
- x86 architecture:
Note those scripts are just aliases so one doesn't need to remember the docker incantation. Also, if you have an older version of docker, you may need to use docker-compose instead of docker compose. That should also work.
Tests for success:
- go to http://0.0.0.0:15672/ - it should look like this:
- Username/password for the dev rabbit broker: smqPublic/smqPublic - [More info]](https://gridworks.readthedocs.io/en/latest/gridworks-broker.html) on the GridWorks use of rabbit brokers
- Test mqtt access via mqtt_sub:
mosquitto_sub -h localhost -p 1885 -u smqPublic -P smqPublic -t "#" -v
and go to http://0.0.0.0:15672/queues to confirm a new queue has showed up
docker exec -it gw-dev-rabbit rabbitmq-plugins list
And confirm: [E*] rabbitmq_mqtt 3.9.13
- tests pass
poetry install
poetry shell
pytest -v
This, and most other GridWorks repositories, use poetry installed via pipx to handle package management. They are also kicked off via Cookiecutter, which also sets up a template for continuous integration in github actions, package publishing on pypi as well as documentation at pypi.
TODO: EXPLAIN MORE ABOUT CI, BLACK, NOX, DEPENDABOT. A MORE LINKS TO WHY THIS STUFF IS IMPORTANT IN A PRODUCTION SYSTEM.
Quick start for seeing how the actor base can send a message on the rabbit broker. Run hello_rabbit.py (after starting up the dev rabbit broker, see dev broker above) and look at the src/gwbase/actor_base.py code.
TODO: explain more about what this code does. Links to the type registroy, code generation. TODO: create a second hello script with two actors sending heartbeats back and forth.
Distributed under the terms of the MIT license, Gridworks Base is free and open source software.
This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.