Implement Batching and handle_batch/4

Learn to implement batching and use the handle_batch/4 callback function to receive the batches.

Implement batching

The tickets application currently handles several types of events and creates records in the database for each. We use batching to group the incoming events by type and insert them all together.

To start using batching, we need to add a configuration to enable it. We can then implement the handle_batch/4 callback—the last callback on our list.

Just like handle_message/3, handle_batch/4 is special, and all code within the callback runs concurrently in a separate batch processor. Batching works by configuring one or more batchers. Each batcher starts a single batch processor by default, which runs the code in handle_batch/4 to process the given group of messages.

Add the :batchers key

Let’s add the :batchers key first:

Get hands-on with 1200+ tech skills courses.