GCP Cloud Pub/Sub Resources

Resources for Google Cloud Pub/Sub. Available resources include:

Example Usage

Create a Pub/Sub Topic

1
import launchflow as lf
2
3
# Automatically creates / connects to a PubSub Topic in your GCP project
4
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
5
6
topic.publish(b"Hello, world!")

Create a Pub/Sub Subscription

1
import launchflow as lf
2
3
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
4
# Automatically creates / connects to a PubSub Subscription in your GCP project
5
subscription = lf.gcp.PubsubSubscription("my-pubsub-sub", topic=topic)

PubsubTopic

A GCP Cloud Pub/Sub Topic.

Like all Resources, this class configures itself across multiple Environments.

For more information see the official documentation.

Example Usage

1
import launchflow as lf
2
3
# Automatically creates / connects to a PubSub Topic in your GCP project
4
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
5
6
topic.publish(b"Hello, world!")

initialization

Create a new PubsubTopic resource.

Args:

  • name (str): The name of the PubsubTopic resource.
  • message_retention_duration (Optional[datetime.timedelta]): The message retention duration for the topic.

Raises:*:

  • ValueError: If the message retention duration is not within the allowed range.

publish

1
PubsubTopic.publish(data: bytes, ordering_key: str = "")

Publish a message to the topic.

Args:

  • data (bytes): The bytes to publish in the message.
  • ordering_key (str): An optional ordering key for the message.

Returns:

  • The result of the publish operation.

Raises:*:

  • ImportError: If the google-cloud-pubsub library is not installed.

Example usage:

1
import launchflow as lf
2
3
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
4
5
topic.publish(b"Hello, world!")

publish_async

1
async PubsubTopic.publish_async(data: bytes, ordering_key: str = "")

Asynchronously publish a message to the topic.

Args:

  • data (bytes): The bytes to publish in the message.
  • ordering_key (str): An optional ordering key for the message.

Returns:

  • The result of the publish operation.

Raises:*:

  • ImportError: If the google-cloud-pubsub library is not installed.

Example usage:

1
import launchflow as lf
2
3
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
4
5
await topic.publish_async(b"Hello, world!")

PubsubSubscription

A GCP Cloud Pub/Sub Subscription.

Like all Resources, this class configures itself across multiple Environments.

For more information see the official documentation.

Example Usage

1
import launchflow as lf
2
3
topic = lf.gcp.PubsubTopic("my-pubsub-topic")
4
# Automatically creates / connects to a PubSub Subscription in your GCP project
5
subscription = lf.gcp.PubsubSubscription("my-pubsub-sub", topic=topic)

initialization

Create a new PubsubSubscription resource.

Args:

  • name (str): The name of the PubsubSubscription resource.
  • topic (Union[PubsubTopic, str]): The topic to subscribe to.
  • push_config (Optional[PushConfig]): The push configuration for the subscription.
  • ack_deadline_seconds (int): The acknowledgment deadline for the subscription.
  • message_retention_duration (datetime.timedelta): The message retention duration for the subscription.
  • retain_acked_messages (bool): Whether to retain acknowledged messages.
  • filter (Optional[str]): The filter for the subscription.

Raises:*:

  • ValueError: If the topic is not a PubsubTopic or a str.