|
1 | 1 | # ampq-restapi |
2 | 2 | A simple restapi for sending messages to an ampq based message broker |
| 3 | + |
| 4 | +This app is a simple REST API that allows you to send messages to an AMQP-based message broker. based on aiopika and |
| 5 | +FastAPI. |
| 6 | + |
| 7 | +This was designed to be used with RabbitMQ, but likely will work with any AMQP-based message broker. |
| 8 | + |
| 9 | +## Usage |
| 10 | +### Dependencies |
| 11 | +- Python 3.11+ |
| 12 | +- pip |
| 13 | + |
| 14 | +### Environment Variables |
| 15 | +- `RPC_URI`: The URI of the message broker. E.G `amqp://guest:guest@localhost/` |
| 16 | +- `PORT`: The port to run the application on. (Default: 2000) |
| 17 | + |
| 18 | +### Docker |
| 19 | +You cause pull the container from Github container registry |
| 20 | +```bash |
| 21 | +docker pull ghcr.io/iplsplatoon/ampq-restapi:master |
| 22 | +``` |
| 23 | + |
| 24 | +or use `ghcr.io/iplsplatoon/ampq-restapi:master` as the image name in your docker-compose file. |
| 25 | + |
| 26 | +### Install: Bare Metal |
| 27 | +1. Install python dependencies with pip |
| 28 | + ```bash |
| 29 | + pip install -r requirements.txt |
| 30 | + ``` |
| 31 | + |
| 32 | +3. Run the application |
| 33 | + ```bash |
| 34 | + python -m restapi |
| 35 | + ``` |
| 36 | + |
| 37 | +### Making requests |
| 38 | +The application will run on port 2000 by default. |
| 39 | + |
| 40 | +#### Docs |
| 41 | +The application is documented using OpenAPI. |
| 42 | +You can view the documentation by navigating to `http://localhost:2000/docs` in your web browser. |
| 43 | + |
| 44 | +#### Send a message |
| 45 | +You can make a **POST** request to the `/rpc/response` endpoint with the following query parameters: |
| 46 | + |
| 47 | +- `routing_key`: The routing key to use for the message. This is a required parameter. |
| 48 | +- `timeout`: The timeout for the request in seconds. (Default: Never) |
| 49 | + |
| 50 | +You message body should be what ever you want to be sent, the app will convert this to a byte string and send it as the |
| 51 | +message body. We also use the `content_type` header to set the content type of the message that send to the message broken. |
| 52 | + |
| 53 | +The response will be send back to what ever client you using back and will forward the body, headers and other |
| 54 | +properties from the response message. |
| 55 | + |
| 56 | +_If you don't need a response, you can use the `/rpc/one_way` endpoint instead._ |
| 57 | +
|
| 58 | +## Development |
| 59 | +
|
| 60 | +### Dependencies |
| 61 | +PDM is used for dependency management. |
| 62 | +
|
| 63 | +To install dependencies, run the following command: |
| 64 | +```bash |
| 65 | +pdm install |
| 66 | +``` |
| 67 | +
|
| 68 | +### Linting |
| 69 | +We use `ruff` for linting and formatting. You can run the following command to lint and format the code: |
| 70 | +```bash |
| 71 | +ruff check |
| 72 | +ruff format |
| 73 | +``` |
0 commit comments