https://github.com/bankole2000/pocketbase-rabbitmq-extension
Pocketbase extended with golang to publish events to rabbitmq
https://github.com/bankole2000/pocketbase-rabbitmq-extension
Last synced: over 1 year ago
JSON representation
Pocketbase extended with golang to publish events to rabbitmq
- Host: GitHub
- URL: https://github.com/bankole2000/pocketbase-rabbitmq-extension
- Owner: Bankole2000
- Created: 2024-04-24T05:28:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-01T15:29:09.000Z (about 2 years ago)
- Last Synced: 2025-04-09T18:13:22.210Z (over 1 year ago)
- Language: Go
- Size: 746 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
## Pocketbase Extended with Go + RabbitMQ
### A simple Pocketbase RabbitMQ publisher extension template
![Publishing with Rabbit MQ][demo-gif]
### What it does
- Publish any and all events from pocketbase to rabbitmq exchange
- Select and customize published events
- Useful for multiple scenarios like data replication, horizontal scaling, single source of truth accross microservices, async data processing & event handling etc
### Prerequisites
- [Golang](https://go.dev/) >= v1.19
- [RabbitMQ](https://www.rabbitmq.com/) (Running locally or in the cloud)
- [NodeJS](https://nodejs.org) (Optional - for testing the listener)
### Setup & installation
1. Clone or fork this repository (or use this template)
```sh
git clone https://github.com/bankole2000/pb-rmq-ext.git
```
2. init go dependencies in `/pocketbase-publisher` folder
```bash
# in /pocketbase-publisher folder
go mod init && go mod tidy
# Note: can be whatever you want but
# will be name of the executable file created on build
```
3. install node dependences in `/listener-demo` folder (optional)
```sh
# in /listener-demo folder
npm i
```
4. Following the example in `.env.example` Create `.env` file in the root folder and fill in environemental
```SH
# in /.env file
RABBITMQ_URL="amqp://:@:/"
RABBITMQ_EXCHANGE="my-exchange"
# replace with your rabbitmq url and any name you wish to give the exchange
```
#### No RabbitMQ? No problem
This step requires [docker](https://www.docker.com/) - To get a local instance of Rabbitmq running simply run
```docker
docker run -d --hostname localhost -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq:3-management
```
Or run `docker compose up` using [this docker compose yml file](./media/docker-compose.yml)
### How To Use
1. Start the pocketbase application
```sh
# in /pocketbase-publisher folder
go run main.go serve
```
2. Start up the message/event listener
```sh
# in /listener-demo
npm run dev
```
3. Use the pocketbase api or sdk or admin (running on `http://127.0.0.1:8090/_/`) as you normally would (creating collections, records etc) and watch the events logged by the listener.
4. To build a statically linked single file application, you can run
```sh
# create build file
CGO_ENABLED=0 go build
# run created executable
./my-app serve
```
> ⚠ Warning: If you run into any `gcc failed` errors running `go run main.go serve` , try setting `CGO_ENABLED=0` environment variable according to the [pocketbase docs here](https://pocketbase.io/docs/go-overview/)
> 📝 Note: in the `/pocketbase-publisher/main.go` file, you can also change the values of `rmqUrl` and `exchange` variables on _lines 55_ and _56_ to the string values of your rabbitmq Url and the exchange name. This way the build won't rely on the `.env` file to run (be sure to delete or comment out the `goDotEnvVariable` function in _line 39_)
## Contributing
Any contributions you make are **greatly appreciated**.
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'feat: added some amazing feature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
## Contact
📧 Shoot me an email -
🌎 My Website - [The Neon Coder](https://bankole2000.github.io/webpieces)
💼 Project Link: [https://github.com/bankole2000/pocketbase-rabbitmq-extension](https://github.com/bankole2000/pocketbase-rabbitmq-extension)
[demo-gif]: ./media/publisher.gif