Hey, Good idea bad pitch, lets use Git as a messaging queue! lets use github to synchronize a cluster of them together.
Lets get the obvious out of the way, You already know we use Git to keep track of our code changes, and we need a central point to pull and push these changes, this is why we use github/lab/bitbucket…etc.
Alright, now lets introduce another idea: Git commits doesn’t need to include changes, so you don’t need to have to create files then commit these files to your git repo, you can create an empty commit with a command like this
git commit --allow-empty -m "commit message"
OK, so the commit message can be any text right? that means you can have JSON messages or YAML or any other machine readable format as a commit message.
So now imagine this scenario:
- Create a repo on github
- Clone it to your server
- Have your application commit a
messageto this repo every time you need to
- Push the repo every period say 10 seconds
- Clone same repo to another server
- Have an application there (consumer) pull periodically
- Another thread there that checks for new commits and for each one of them extracts the message and does the job
- Put a label on the processed message with that server identifier
- Push that label to keep track of the last processed message (pull it when you deploy that consumer again)
Now you have a queue of messages that can’t be altered, communicated between servers and all data saved in a git repository.
This idea is flexible and can be modified for several use cases:
- the central server doesn’t have to be a github or a like, you can use your own server as a git server.
- You can have more than one queue for messages by creating many branches each for a type of messages or a different messages purpose.
- You can have the same branch consumed from different servers each message processed multiple times in different ways like RabbitMQ fan out strategy
- You can keep browse your message queue with any git client UI or CLI
- You can clean your servers git local repo so that it deletes old commit history to save space.
- You can have many messages producers write to different branches in the same repository
- In the future you can join 2 branches or split a branch and have your consumers adapt to that
This idea can as simple as invoking git commands from your application with a system call, or use libgit to manipulate the repository for you, or even a small server application that communicate over a socket, or a repo service that communicate over even HTTP, there are so many ways to implement that concept.