BroadwayCloudPubSub.Client behaviour (BroadwayCloudPubSub v1.0.0)

Copy Markdown View Source

A generic behaviour to implement Pub/Sub Clients for BroadwayCloudPubSub.Producer.

This module defines callbacks to normalize options and receive messages from a Cloud Pub/Sub topic. Modules that implement this behaviour should be passed as the :client option from BroadwayCloudPubSub.Producer.

Summary

Types

The amount of time (in seconds) before Pub/Sub should reschedule a message.

The ackId returned by Pub/Sub to be used when acknowledging a message.

A list of ackId strings.

A list of Broadway.Message structs.

Types

ack_deadline()

@type ack_deadline() :: 0..600

The amount of time (in seconds) before Pub/Sub should reschedule a message.

ack_id()

@type ack_id() :: String.t()

The ackId returned by Pub/Sub to be used when acknowledging a message.

ack_ids()

@type ack_ids() :: [ack_id()]

A list of ackId strings.

messages()

@type messages() :: [Broadway.Message.t()]

A list of Broadway.Message structs.

Callbacks

acknowledge(ack_ids, opts)

(optional)
@callback acknowledge(ack_ids(), opts :: any()) :: any()

Dispatches an acknowledge request.

init(opts)

@callback init(opts :: any()) ::
  {:ok, normalized_opts :: any()} | {:error, message :: binary()}

prepare_to_connect(name, producer_opts)

(optional)
@callback prepare_to_connect(name :: atom(), producer_opts :: keyword()) ::
  {[:supervisor.child_spec() | {module(), any()} | module()],
   producer_opts :: keyword()}

Invoked once by BroadwayCloudPubSub.Producer during Broadway.start_link/2.

The goal of this task is to manipulate the producer options, if necessary at all, and introduce any new child specs that will be started in Broadway's supervision tree.

put_deadline(ack_ids, ack_deadline, opts)

(optional)
@callback put_deadline(ack_ids(), ack_deadline(), opts :: any()) :: any()

Dispatches a modifyAckDeadline request.

receive_messages(demand, ack_builder, opts)

@callback receive_messages(
  demand :: pos_integer(),
  ack_builder :: (ack_id() -> term()),
  opts :: any()
) ::
  messages()

Dispatches a pull request.