TIPCommon.adapters
class TIPCommon.adapters.pubsub.pubsub.PubSubAdapter
class TIPCommon.adapters.pubsub.pubsub.PubSubAdapter(service_account, project_id=None, verify_ssl=True, logger=None)
Bases: object
Adapter class for managing Google Cloud project Pub/Sub topics and subscriptions.
ack
ack(sub_name, ack_ids)
Acknowledges the messages associated with the ackIDs
in the AcknowledgeRequest
response returned from PubSubAdapter.pull()
.
Parameters | |
---|---|
sub_name |
str The subscription name. |
ack_ids |
list[str]
List of acknowledgment IDs ( |
static build_pubsub_message
static build_pubsub_message(message_content, encoding='utf-8', ordering_key=None, **attr)
Creates a PubSubMessage object.
Parameters | |
---|---|
message_content |
str Message text content. |
encoding |
str Encoding type to encode or decode the message text. Default is UTF-8. |
ordering_key |
Optional
If non-empty, identifies related messages for which the publish order should be followed. |
**attr |
Optional
Attributes to pass as message object attributes. |
Returns
TIPCommon.adapters.pubsub.PubSubMessage
object.
Return type
create_subscription
create_subscription(sub_name, topic, **attr)
Creates a Pub/Sub subscription for the specified topic.
Parameters | |
---|---|
sub_name |
str Subscription name identifier. |
topic |
str A Pub/Sub topic name to create the subscription for. |
**attr |
Additional parameters to pass to the subscription request. |
Returns
TIPCommon.adapters.pubsub.Subscription
object of the created subscription.
Return type
create_topic
create_topic(topic_name)
Creates a Pub/Sub topic in a Google Cloud project.
Parameters | |
---|---|
topic_name |
str Name of the topic to be created. Must correspond to the Google Cloud resource name rules. |
Returns
TIPCommon.adapters.pubsub.Topic
object of the created topic.
Return type
delete_subscription
delete_subscription(sub_name)
Deletes a Pub/Sub subscription from a Google Cloud project.
Parameters | |
---|---|
sub_name |
str The subscription name to remove. |
delete_topic
delete_topic(topic_name)
Deletes a Pub/Sub topic from a Google Cloud project.
Parameters | |
---|---|
topic_name |
str The topic to remove. |
get_subscription
get_subscription(sub_name, topic=None, create_if_not_exist=False, **attr)
Retrieves a Pub/Sub subscription.
Parameters | |
---|---|
sub_name |
str The subscription name identifier. |
topic |
str A Pub/Sub topic name to create a
subscription for. Mandatory if |
create_if_not_exist |
Creates the Pub/Sub subscription in Google Cloud, if it doesn't exist. |
**attr |
Additional parameters to pass to the subscription creation request. |
Returns
TIPCommon.adapters.pubsub.Subscription
object of the retrieved subscription.
Return type
get_topic
get_topic(topic_name, create_if_not_exist=False)
Retrieves a Pub/Sub topic object from the configured Google Cloud project.
Parameters | |
---|---|
topic_name |
str Name of the topic (simplified, without the
|
create_if_not_exist |
bool Creates the Pub/Sub topic in Google Cloud, if it does not exist. |
Returns
TIPCommon.adapters.pubsub.Topic
object of the received topic.
Return type
patch_subscription
patch_subscription(sub_name, topic_name, push_config=None, bigquery_config=None, cloud_storage_config=None, ack_deadline_seconds=None, retain_acked_messages=None, retention_duration=None, labels=None, enable_message_ordering=None, expiration_policy=None, query_filter=None, dead_letter_policy=None, return_policy=None, detached=None, enable_once_delivery=None)
Updates an existing subscription.
Parameters | |
---|---|
sub_name |
str The subscription name. |
topic_name |
str The name of the topic from which this subscription is receiving messages. |
Returns
TIPCommon.adapters.pubsub.Subscription
object of the received subscription.
Return type
patch_topic
patch_topic(topic_name, labels=None, message_storage_policy=None, kms_key_name=None, schema_settings=None, satisfies_pzs=None, retention_duration=None)
Updates an existing topic.
Parameters | |
---|---|
topic_name |
str The topic name. |
Returns
TIPCommon.adapters.pubsub.Topic
object of the received topic.
Return type
publish
publish(topic_name, messages)
Publish a list of PubSubMessage objects to a topic.
Parameters | |
---|---|
topic_name |
str The name of the topic to publish the messages. |
messages |
list List of PubSubMessage objects.
Can be created with the |
Returns
List of message IDs.
Return type
list[str]
pull
pull(sub_name, limit, timeout=60, encoding='utf-8')
Pull messages from Pub/Sub subscriptions.
Parameters | |
---|---|
sub_name |
str The subscription name. |
limit |
int The maximum number of messages to return for this request. |
timeout |
int HTTP request timeout in seconds. Default is 60 seconds. |
encoding |
str A Pub/Sub message encoding. Default
is |
Returns
List of TIPCommon.adapters.pubsub.ReceivedMessage
objects.
Return type
list[ReceivedMessage]
static subscription_name
static subscription_name(project_id, sub_name)
Retrieves the full subscription name in the following format: projects/project_id
/subscriptions/subscription_name
.
Parameters | |
---|---|
project_id |
str The project name containing the resource. |
sub_name |
str A Pub/Sub subscription name. |
Returns
A full subscription name in the following format:
projects/project_id
/subscriptions/subscription_name
.
Return type
str
static topic_name
static topic_name(project_id, topic)
Retrieves projects/project_id
/topics/topic_name
.
Parameters | |
---|---|
project_id |
str The project name that contains the resource. |
topic |
str A Pub/Sub topic name. |
Returns
A full topic name: projects/project_id
/topics/topic_name
.
Return type
str
class TIPCommon.adapters.pubsub.data_models.PubSubMessage
class TIPCommon.adapters.pubsub.data_models.PubSubMessage(raw_data: 'dict', data: 'str' = None, attributes: 'dict' = None, message_id: 'str' = None, publish_time: 'int' = None, ordering_key: 'str' = None)
Bases: object
attributes: dict= None
data: str= None
json()
message_id: str= None
ordering_key: str= None
publish_time: int= None
raw_data: dict
class TIPCommon.adapters.pubsub.data_models.ReceivedMessage
class TIPCommon.adapters.pubsub.data_models.ReceivedMessage(raw_data: 'dict', ack_id: 'str', message: 'PubSubMessage', delivery_attempt: 'int')
Bases: object
ack_id: str
delivery_attempt: int
json()
message: PubSubMessage
raw_data: dict
class TIPCommon.adapters.pubsub.data_models.SchemaSettings
class TIPCommon.adapters.pubsub.data_models.SchemaSettings(raw_data: 'dict', schema: 'str', encoding: 'str' = None, first_revision_id: 'str' = None, last_revision_id: 'str' = None)
Bases: object
encoding: str= None
first_revision_id: str= None
json()
last_revision_id: str= None
raw_data: dict
schema: str
class TIPCommon.adapters.pubsub.data_models.Subscription
class TIPCommon.adapters.pubsub.data_models.Subscription(raw_data: 'dict', name: 'str', identifier: 'str', topic_identifier: 'str', state: 'str', ack_deadline_secs: 'int' = None, retain_ack_messages: 'bool' = None, message_retention_duration: 'int' = None, labels: 'dict' = None, message_ordering: 'bool' = None, query_filter: 'str' = None, topic_message_retention_duration: 'int' = None)
Bases: object
ack_deadline_secs: int= None
identifier: str
json()
labels: dict= None
message_ordering: bool= None
message_retention_duration: int= None
name: str
query_filter: str= None
raw_data: dict
retain_ack_messages: bool= None
state: str
topic_identifier: str
topic_message_retention_duration: int= None
class TIPCommon.adapters.pubsub.data_models.Topic
class TIPCommon.adapters.pubsub.data_models.Topic(raw_data: 'dict', name: 'str', identifier: 'str', labels: 'dict' = None, schema_settings: 'SchemaSettings' = None, message_retention_duration: 'int' = None)
Bases: object
identifier: str
json()
labels: dict= None
message_retention_duration: int= None
name: str
raw_data: dict
schema_settings: SchemaSettings= None