Topics in Phoenix are a form of implementing the publisher-subscriber pattern.
In this recipe, we will create a simple counter in a form of a function that will subscribe a channel.
TodosController, we will broadcast an event every time a request is made to the index action. The counter will then receive the notification and will output a message to the console with the number of times the action was called.
To get started, we will take the code resulting from the previous recipe. Open a code editor and prepare to add pub/sub to the Phoenix application.
To implement topics in the Phoenix application, follow these steps:
TodoControllerto make it look like this:
defmodule Todo.TodosController do use ...