The Details of Broadway Callbacks
Learn to add functionality to the tickets project and start receiving messages from the message broker.
Now that we have the tickets project set up, we can start writing some code. Once a message comes from the message broker, we want to use it to create a ticket in the database for the customer and send a confirmation email to them.
Broadway
callbacks
To accomplish this, we will use the Broadway
behavior to configure and start the data-ingestion pipeline. There are four callbacks available for us to implement:
-
handle_message/3
-
prepare_messages/2
-
handle_failed/2
-
handle_batch/4
This section will focus on the first three callbacks in the list.
Create bookings_pipeline.ex
First, we create a new file, bookings_pipeline.ex
, in the lib
folder. Then, we define the BookingsPipeline
module in the following way:
defmodule BookingsPipeline do
use Broadway
end
We also add use Broadway
to bring in the Broadway
...