As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

Publisher Client API

class google.cloud.pubsublite.cloudpubsub.publisher_client.AsyncPublisherClient(*, per_partition_batching_settings: Optional[google.cloud.pubsub_v1.types.BatchSettings] = None, credentials: Optional[google.auth.credentials.Credentials] = None, transport: str = 'grpc_asyncio', client_options: Optional[google.api_core.client_options.ClientOptions] = None, enable_idempotence: bool = False)[source]

An AsyncPublisherClient publishes messages similar to Google Pub/Sub, but must be used in an async context. Any publish failures are unlikely to succeed if retried.

Must be used in an async with block or have __aenter__() awaited before use.

Create a new AsyncPublisherClient.

Parameters
  • per_partition_batching_settings – The settings for publish batching. Apply on a per-partition basis.

  • credentials – If provided, the credentials to use when connecting.

  • transport – The transport to use. Must correspond to an asyncio transport.

  • client_options – The client options to use when connecting. If used, must explicitly set api_endpoint.

  • enable_idempotence – Whether idempotence is enabled, where the server will ensure that unique messages within a single publisher session are stored only once.

DEFAULT_BATCHING_SETTINGS = BatchSettings(max_bytes=3145728, max_latency=0.05, max_messages=1000)

The default batching settings for a publisher client.

async __aenter__()[source]

Return self upon entering the runtime context.

async __aexit__(exc_type, exc_value, traceback)[source]

Raise any exception triggered within the runtime context.

async publish(topic: Union[google.cloud.pubsublite.types.paths.TopicPath, str], data: bytes, ordering_key: str = '', **attrs: Mapping[str, str]) str[source]

Publish a message.

Parameters
  • topic – The topic to publish to. Publishes to new topics may have nontrivial startup latency.

  • data – The bytestring payload of the message

  • ordering_key – The key to enforce ordering on, or “” for no ordering.

  • **attrs – Additional attributes to send.

Returns

An ack id, which can be decoded using MessageMetadata.decode.

Raises

GoogleApiCallError – On a permanent failure.

class google.cloud.pubsublite.cloudpubsub.publisher_client.PublisherClient(*, per_partition_batching_settings: Optional[google.cloud.pubsub_v1.types.BatchSettings] = None, credentials: Optional[google.auth.credentials.Credentials] = None, transport: str = 'grpc_asyncio', client_options: Optional[google.api_core.client_options.ClientOptions] = None, enable_idempotence: bool = False)[source]

A PublisherClient publishes messages similar to Google Pub/Sub. Any publish failures are unlikely to succeed if retried.

Must be used in a with block or have __enter__() called before use.

Create a new PublisherClient.

Parameters
  • per_partition_batching_settings – The settings for publish batching. Apply on a per-partition basis.

  • credentials – If provided, the credentials to use when connecting.

  • transport – The transport to use. Must correspond to an asyncio transport.

  • client_options – The client options to use when connecting. If used, must explicitly set api_endpoint.

  • enable_idempotence – Whether idempotence is enabled, where the server will ensure that unique messages within a single publisher session are stored only once.

DEFAULT_BATCHING_SETTINGS = BatchSettings(max_bytes=3145728, max_latency=0.05, max_messages=1000)

The default batching settings for a publisher client.

__enter__()[source]

Return self upon entering the runtime context.

__exit__(exc_type, exc_value, traceback)[source]

Raise any exception triggered within the runtime context.

publish(topic: Union[google.cloud.pubsublite.types.paths.TopicPath, str], data: bytes, ordering_key: str = '', **attrs: Mapping[str, str]) concurrent.futures._base.Future[str][source]

Publish a message.

Parameters
  • topic – The topic to publish to. Publishes to new topics may have nontrivial startup latency.

  • data – The bytestring payload of the message

  • ordering_key – The key to enforce ordering on, or “” for no ordering.

  • **attrs – Additional attributes to send.

Returns

A future completed with an ack id of type str, which can be decoded using MessageMetadata.decode.

Raises

GoogleApiCallError – On a permanent failure.