broker_utils.consumer_sim

Simulate the consumer by publishing alerts to a Pub/Sub topic.

broker.broker_utils.broker_utils.consumer_sim.publish_stream(alert_rate, instance=None, runtime=None, publish_batch_every=(5, 'sec'), sub_id=None, topic_id=None, nack=False, auto_confirm=False)[source]

Pulls messages from from a Pub/Sub subscription determined by either instance or sub_id, and publishes them to a topic determined by either instance or topic_id. Specific options are described in the docs.

Parameters
  • alert_rate (Union[Tuple[int, str], str]) – Desired rate at which alerts will be published.

  • instance (Optional[Tuple[str, str]]) – (survey, testid). Keywords of the broker instance. Used to determine the subscription and topic. If None, sub_id and topic_id must be valid names. If both instance and sub_id/topic_id are passed, sub_id/topic_id will prevail.

  • runtime (Optional[Tuple[int, str]]) – Desired length of time simulator runs for.

  • publish_batch_every (Tuple[int, str]) – Simulator will sleep for this amount of time between batches

  • sub_id (Optional[str]) – Name of the Pub/Sub subscription from which to pull alerts. If None, instance must contain valid keywords, and then the production instance reservoir ‘{survey}-alerts-reservoir’ will be used.

  • topic_id (Optional[str]) – Name of the Pub/Sub topic to which alerts will be published. If None, instance must contain valid keywords, and then the topic ‘{survey}-alerts-{testid}’ will be used.

  • nack (bool) – Whether to “nack” (not acknowledge) the messages. If True, messages are published to the topic, but they are not dropped from the subscription and so will be delivered again at an arbitrary time in the future.

  • auto_confirm (bool) – Whether to automatically answer “Y” to the confirmation prompt.