Course lesson 23 · Working with Queues

Building Type Safe Queue Handlers

One study unit · Read, recall, then practice · Original video 00:11:00

The queue consumer now validates incoming messages and routes recognised event types to dedicated handlers. A Zod discriminated union turns the event’s type label into a dependable choice of payload shape, and the first handler persists link-click data to D1 through the shared DataOps package. This creates an end-to-end path from a visitor’s click to a queryable database record.

Primary source: course video 23 · Supplied English subtitles · 00:11:00.

Understand the idea

What the course does

  1. Inspect the common queue envelope and the specific link-click schema in DataOps.
  2. Validate each message body with the queue schema’s safeParse operation.
  3. Log validation errors for unrecognised or malformed messages in the course implementation.
  4. Create the add-link-click query that inserts the event fields into the link-clicks table, then rebuild DataOps.
  5. Add a link-click handler that calls the shared query, and await it from the consumer after checking the event type.
  6. Deploy, visit a known smart link, and query D1 to confirm that a real click record appears.

Watch for

Recall before revealing

Why validate messages if the producer already uses a TypeScript type?

Reveal the explanation

Types are development-time checks; the actual queue payload can still be malformed or come from a different producer or version.

Try it

Describe a second event type that could use the same queue. Specify its type label, required fields, and dedicated handler responsibility.

Check your result

Your new type has a distinct schema and handler, and adding it does not require mixing its business logic into the existing link-click handler.

Practice prompts and answer checks are added teaching material. Answer from memory first, then compare and explain any difference.

Rewatch only what you need

Open this lesson in your original course library and seek to the times below. Videos are not hosted on this site.

Companion primary documentation: Queues delivery guarantees. For recorded API names, commands, limits, and prices, check the version you use.

← Previous   Next →