Broadway.test_message
test_message
, go back to Broadway module for more information.
Specs
Sends a test message through the Broadway pipeline.
This is a convenience used for testing. The given data
is automatically wrapped in a Broadway.Message
with
Broadway.CallerAcknowledger
configured to send a message
back to the caller once the message has been fully processed.
The message is set to be flushed immediately, without waiting
for the Broadway pipeline batch_size
to be filled or the
batch_timeout
to be triggered.
It returns a reference that can be used to identify the ack messages.
See "Testing" section in module documentation for more information.
Options
:metadata
- optionally a map of additional fields to add to the message. This can be used, for example, when testingBroadwayRabbitMQ.Producer
.:acknowledger
- optionally a function that generatesack
fields ofBroadway.Message.t()
that is sent. This function should have following spec(data :: term, {pid, reference()} -> {module, ack_ref :: term, data :: term})
.
Examples
For example, in your tests, you may do:
ref = Broadway.test_message(broadway, 1)
assert_receive {:ack, ^ref, [successful], []}
or if you want to override which acknowledger shall be called, you may do:
acknowledger = fn data, ack_ref -> {MyAck, ack_ref, :ok} end
Broadway.test_message(broadway, 1, acknowledger: acknowledger)
Note that messages sent using this function will ignore demand and :transform
option specified in :producer option in Broadway.start_link/2
.