Firehose is an example of how you can use SSE and Redis (redix) to push events from Redis Pub/Sub to a server-sent events HTTP stream using Elixir with deployment using distillery. (+ configs on how you can easily deploy to Kubernetes!)
Plug router, implementing Plug.Router, sets up a /pipe route which is the main entry point for SSE. It streams events coming from the EventBus channel as described below. It also sets up a /infra/nodes route which lists the nodes on the Erlang cluster for debugging, if running in cluster mode
GenServer which subscribes to a Redis channel, then on Pub/Sub message recieve, it assumes the message is in JSON format, then tries to deserialize the string into JSON using Poison. It then sends the message to an EventBus.
General-purpose supervisor for setting up Plug and starting the Redis listener.
Configures SSE, EventBus, and https://github.com/bitwalker/libcluster for production using the Kubernetes strategy. Polls the K8s API every 10 seconds for nodes using the selector app=firehose.
Kubernetes deployment configuration file which fetches a docker image and sets envoronment variables for the port Plug will serve on, and variables that libcluster requires. It also sets Erlang cluster variables, such as the cookie so the nodes in the clusters can communicate if needed.
Sets up a Kubernetes ingress which finds Firehose instances and serves them on port 80.
Deploys roles on Kubernetes using rbac.authorization which gives the Firehose nodes access and permissions to use the in-cluster Kuberenetes API, which libcluster uses to find other nodes in the Kubernetes cluster, and adds it to the Erlang cluster.
Sets BEAM virtual machine arguments used for Erlang clustering, it takes environment variables as set within the Kubernetes deployment file.
Builds Distillery release and builds Erlang VM bytecode, then exposes port 8080 for Plug and runs the compiled program.