Skip to content

Commit

Permalink
Provide more clarity on the length of list in c:prepare_messages/2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cigrainger committed Jan 18, 2024
1 parent ebee2a9 commit 78ad896
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/broadway.ex
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,15 @@ defmodule Broadway do
by `c:handle_message/3`. For example, if you need to query the database,
instead of doing it once per message, you can do it on this callback.
The length of the list of messages received by this callback is based on
the `min_demand`/`max_demand` configuration in the processor. This callback
must always return all messages it receives, as `c:handle_message/3` is still
called individually for each message afterwards.
The length of the list of messages received by this callback is often based
on the `min_demand`/`max_demand` configuration in the processor but ultimately
it depends on the producer and the frequency data arrives. A pipeline that
receives one message per minute will most likely emit single element lists.
Producers which are push-based, rather than pull-based, such as
`BroadwayRabbitMQ.Producer`, are more likely to send messages as they appear.
This callback must always return all messages it receives, as
`c:handle_message/3` is still called individually for each message afterwards.
"""
@callback prepare_messages(messages :: [Message.t()], context :: term) :: [Message.t()]

Expand Down

0 comments on commit 78ad896

Please sign in to comment.