TrimbleCloud.Events
Table of Contents
Section titled “Table of Contents”- TrimbleCloud.Events
- TrimbleCloud.Events.Core.Session
- TrimbleCloud.Events.Models.Event
- TrimbleCloud.Events.Models.ConsumeEvent
- TrimbleCloud.Events.Models
- TrimbleCloud.Events.Models.Response
- TrimbleCloud.Events.Models.ConnectionStatus
- TrimbleCloud.Events.Models.PublishEvent
- TrimbleCloud.Events.Models.KafkaResponse
- TrimbleCloud.Events.Models.EventsBatch
- TrimbleCloud.Events.Models.Workflow
- TrimbleCloud.Events.Models.BatchAck
- TrimbleCloud.Events.Exceptions.ConsumerException
- TrimbleCloud.Events.Exceptions
- TrimbleCloud.Events.Exceptions.ValidationException
- TrimbleCloud.Events.Exceptions.ConnectionClosedException
- TrimbleCloud.Events.Exceptions.PublisherException
- TrimbleCloud.Events.Exceptions.WebSocketException
TrimbleCloud
Section titled “TrimbleCloud”TrimbleCloud.Events.Core.Session
Section titled “TrimbleCloud.Events.Core.Session”Session
Section titled “Session”class Session()Represents a session for interacting with the Trimble Cloud Events service.
Arguments:
endpointstr - The endpoint URL of the service.client_idstr - The client ID for authentication.client_secretstr - The client secret for authentication.tid_scopestr, optional - The TID scope for authentication. Defaults to None.auth_urlstr - The authentication URL.enable_batchbool, optional - Enable batch processing. Defaults to False.batch_buffer_sizeint, optional - The size of the batch buffer. Required if enable_batch is True.batch_buffer_msint, optional - The time in milliseconds to wait before sending a batch. Required if enable_batch is True.batch_expiry_msint, optional - The time in milliseconds after which a batch expires. Required if enable_batch is True.workflowWorkflow - The workflow type (PUBLISHER or CONSUMER).call_backcallable - The callback function to handle events.retry_countint - The number of times to retry connection.ack_wait_msint, optional - The time in milliseconds to wait for acknowledgement. Required for PUBLISHER workflow with enable_batch is True or CONSUMER workflow.ack_retryint, optional - The number of times to retry acknowledgement. Required for PUBLISHER workflow with enable_batch is True or CONSUMER workflow.client_acknowledgebool, optional - Enable client acknowledgement. Required for CONSUMER workflow.enable_metricsbool - Enable metrics recording.datadog_api_keystr, optional - The API key for Datadog integration. Required if enable_metrics is True.datadog_application_keystr, optional - The application key for Datadog integration. Required if enable_metrics is True.datadog_metrics_tagsdict, optional - The tags for Datadog metrics. Required if enable_metrics is True.metric_recorderstr, optional - The metric recorder type. Required if enable_metrics is True.
Raises:
ValueError- If any required argument is missing or has an invalid value.TypeError- If any argument has an invalid type.
Attributes:
urlstr - The endpoint URL of the service.activebool - Indicates if the session is active.connection_statusStatus - The connection status of the session.
@propertydef url()Returns the endpoint URL for the session.
Returns:
The endpoint URL.
active
Section titled “active”@propertydef active()Check if the session is active.
Returns:
bool- True if the session is active, False otherwise.
connection_status
Section titled “connection_status”@propertydef connection_status()Returns the current connection status of the session.
Returns:
Status- The connection status.
def send(batch)Sends a batch of events to the server.
Arguments:
batchBatch - The batch of events to send.
Raises:
ConnectionClosedException- If the connection is already closed or still connecting.PublisherException- If there is an exception while sending the batch or if the batch does not contain any events.
publish_message
Section titled “publish_message”def publish_message(event)Publishes an event message.
Arguments:
eventEvent - The event object to be published.
Raises:
PublisherException- If batching is disabled.
def poll(event)Polls for an event from the server.
Arguments:
eventEvent - The event to poll for.
Raises:
ConnectionClosedException- If the connection is already closed.ConnectionClosedException- If the connection is still connecting.ConsumerException- If an exception occurs during consume.ConsumerException- If a long poll is already in progress.
Returns:
None
acknowledge
Section titled “acknowledge”def acknowledge(acknowledgment_id)Method to explicitly acknowledge the receipt of a message with the given acknowledgment ID.
Arguments:
acknowledgment_idstr - The ID of the message to acknowledge.
Raises:
ConnectionClosedException- If the connection is already closed or in the process of connecting.ConsumerException- If an exception occurs while sending the acknowledgment.
def close()Closes the session and stops all associated components.
Returns:
list- A list of events generated during the session.
on_message
Section titled “on_message”def on_message(message, websocket)Handles incoming messages from the websocket.
Arguments:
messagestr - The message received from the websocket.websocket- The websocket object.
Returns:
None
on_error
Section titled “on_error”def on_error(error)Handles the error response received from the server.
Arguments:
errorException - The error response received from the server.
Returns:
None
TrimbleCloud.Events._version
Section titled “TrimbleCloud.Events._version”TrimbleCloud.Events
Section titled “TrimbleCloud.Events”set_stream_logger
Section titled “set_stream_logger”def set_stream_logger(name='ens', level=logging.ERROR, format_string=None)Add a stream handler for the given name and level to the logging module.
By default, this logs all ens messages to stdout.
For debugging purposes a good choice is to set the stream logger to ''
which is equivalent to saying “log everything”.
.. WARNING::
Be aware that when logging anything from 'ens' the full wire
trace will appear in your logs. If your payloads contain sensitive data
this should not be used in production.
Arguments:
name(string): Log namelevel(int): Logging level, e.g.logging.INFOformat_string(str): Log message format
client
Section titled “client”def client(**kwargs)Create a low-level service client by name using the default session.
See :py:meth:boto3.session.Session.client.
TrimbleCloud.Events.Models.Event
Section titled “TrimbleCloud.Events.Models.Event”class Event()Represents an event in the Trimble Cloud Events system.
__init__
Section titled “__init__”def __init__(product_key, namespace, event, event_version, client_id, visibility_timeout=None, additional_fields=None)Initializes a new instance of the Event class.
Arguments:
product_keystr - The product key associated with the event.namespacestr - The namespace of the event.eventstr - The name of the event.event_versionstr - The version of the event.client_idstr - The client ID associated with the event.visibility_timeoutint, optional - The visibility timeout of the event in milliseconds. Defaults to None.additional_fieldsdict, optional - Additional fields associated with the event. Defaults to None.
productKey
Section titled “productKey”@propertydef productKey()The read-only product_key.
namespace
Section titled “namespace”@propertydef namespace()The read-only namespace.
@propertydef event()The read-only event.
eventVersion
Section titled “eventVersion”@propertydef eventVersion()The read-only event_version.
clientId
Section titled “clientId”@propertydef clientId()The read-only client_id.
TrimbleCloud.Events.Models.ConsumeEvent
Section titled “TrimbleCloud.Events.Models.ConsumeEvent”ConsumeEvent
Section titled “ConsumeEvent”class ConsumeEvent(Event)Represents a consumed event.
Inherits from the base Event class and provides additional functionality for consuming events.
Attributes:
-
product_keystr - The product key associated with the event. -
namespacestr - The namespace of the event. -
eventstr - The event name. -
event_versionstr - The version of the event. -
client_idstr - The client ID associated with the event. -
visibility_timeoutint - A period of time to prevent consumer from receiving and processing the message (Minimum value = 3 seconds & Maximum value = 60 minutes) -
additional_fieldsdict - Additional fields associated with the event.Properties:
-
creation_timefloat - The read-only creation time of the event.
Methods:
to_dict()- Converts the ConsumeEvent object to a dictionary.to_json()- Converts the ConsumeEvent object to a JSON string.
creation_time
Section titled “creation_time”@propertydef creation_time()The read-only creation_time.
Returns:
float: The creation time of the event.
to_dict
Section titled “to_dict”def to_dict()Converts the ConsumeEvent object to a dictionary.
Returns:
dict: A dictionary representation of the ConsumeEvent object.
to_json
Section titled “to_json”def to_json()Converts the ConsumeEvent object to a JSON string.
Returns:
str: A JSON string representation of the ConsumeEvent object.
TrimbleCloud.Events.Models
Section titled “TrimbleCloud.Events.Models”TrimbleCloud.Events.Models.Response
Section titled “TrimbleCloud.Events.Models.Response”Response
Section titled “Response”class Response()Represents a response object.
Attributes:
response_typestr - The response type.acknowledgment_idstr - The acknowledgment ID.consumer_group_idstr - The consumer group ID.error_messagestr - The error message.response_messageslist - The list of response messages.consumer_requestNamespace - The consumer request.
get_kafka_response_list
Section titled “get_kafka_response_list”def get_kafka_response_list(response_messages)Get the list of Kafka responses.
Arguments:
response_messageslist - The list of response messages.
Returns:
list- The list of Kafka responses.
__init__
Section titled “__init__”def __init__(message)Initialize a Response object.
Arguments:
messagestr - The response message.
response_type
Section titled “response_type”@propertydef response_type()Get the response type.
Returns:
str- The response type.
acknowledgment_id
Section titled “acknowledgment_id”@propertydef acknowledgment_id()Get the acknowledgment ID.
Returns:
str- The acknowledgment ID.
consumer_group_id
Section titled “consumer_group_id”@propertydef consumer_group_id()Get the consumer group ID.
Returns:
str- The consumer group ID.
error_message
Section titled “error_message”@propertydef error_message()Get the error message.
Returns:
str- The error message.
response_messages
Section titled “response_messages”@propertydef response_messages()Get the list of response messages.
Returns:
list- The list of response messages.
consumer_request
Section titled “consumer_request”@propertydef consumer_request()Get the consumer request.
Returns:
Namespace- The consumer request.
to_dict
Section titled “to_dict”def to_dict()Convert the Response object to a dictionary.
Returns:
dict- The Response object as a dictionary.
to_json
Section titled “to_json”def to_json()Convert the Response object to a JSON string.
Returns:
str- The Response object as a JSON string.
TrimbleCloud.Events.Models.ConnectionStatus
Section titled “TrimbleCloud.Events.Models.ConnectionStatus”Status
Section titled “Status”class Status(enum.Enum)Represents the connection status.
Attributes:
RUNNING- The connection is currently running.STOPPED- The connection has been stopped.CONNECTING- The connection is in the process of connecting.
TrimbleCloud.Events.Models.PublishEvent
Section titled “TrimbleCloud.Events.Models.PublishEvent”PublishEvent
Section titled “PublishEvent”class PublishEvent(Event)Represents a publish event.
Inherits from the base Event class and provides additional functionality for publishing events.
Arguments:
product_keystr - The product key.namespacestr - The namespace.eventstr - The event.event_versionstr - The event version.client_idstr - The client ID.entity_idstr - The entity ID.payloaddict - The payload.
Attributes:
connIdstr - The connection ID.idstr - The ID.topicNamestr - The topic name.feedbackstr - The feedback.
entityId
Section titled “entityId”@propertydef entityId()The read-only entity_id.
payload
Section titled “payload”@propertydef payload()The read-only payload.
to_dict
Section titled “to_dict”def to_dict()Convert the PublishEvent object to a dictionary.
Returns:
dict- The PublishEvent object as a dictionary.
from_response
Section titled “from_response”@classmethoddef from_response(response_message)Create a PublishEvent object from a response message.
Arguments:
response_messagestr - The response message.
Returns:
PublishEvent- The PublishEvent object.
TrimbleCloud.Events.Models.KafkaResponse
Section titled “TrimbleCloud.Events.Models.KafkaResponse”KafkaResponse
Section titled “KafkaResponse”class KafkaResponse()Represents a response from Kafka.
acknowledgment_id
Section titled “acknowledgment_id”@propertydef acknowledgment_id()The read-only acknowledgment_id.
entity_id
Section titled “entity_id”@propertydef entity_id()The read-only entity_id.
message
Section titled “message”@propertydef message()The read-only message.
TrimbleCloud.Events.Models.EventsBatch
Section titled “TrimbleCloud.Events.Models.EventsBatch”EventsBatch
Section titled “EventsBatch”class EventsBatch()creation_time
Section titled “creation_time”@propertydef creation_time()The read-only creation_time.
TrimbleCloud.Events.Models.Workflow
Section titled “TrimbleCloud.Events.Models.Workflow”Workflow
Section titled “Workflow”class Workflow(enum.Enum)Represents the type of workflow.
Attributes:
PUBLISHER- The workflow is a publisher.CONSUMER- The workflow is a consumer.
TrimbleCloud.Events.Models.BatchAck
Section titled “TrimbleCloud.Events.Models.BatchAck”BatchAck
Section titled “BatchAck”class BatchAck()__init__
Section titled “__init__”def __init__(batch_id)Initializes a new instance of the BatchAck class.
Arguments:
batch_idstr - The ID of the batch.
@propertydef type()Gets the read-only type.
Returns:
str- The type.
batch_id
Section titled “batch_id”@propertydef batch_id()Gets the read-only batch ID.
Returns:
str- The batch ID.
to_json
Section titled “to_json”def to_json()Converts the BatchAck object to a JSON string.
Returns:
str- The JSON representation of the BatchAck object.
to_dict
Section titled “to_dict”def to_dict()Converts the BatchAck object to a dictionary.
Returns:
dict- The dictionary representation of the BatchAck object.
TrimbleCloud.Events.Exceptions.ConsumerException
Section titled “TrimbleCloud.Events.Exceptions.ConsumerException”ConsumerException
Section titled “ConsumerException”class ConsumerException(Exception)Exception raised when there is an error in the consumer.
TrimbleCloud.Events.Exceptions
Section titled “TrimbleCloud.Events.Exceptions”TrimbleCloud.Events.Exceptions.ValidationException
Section titled “TrimbleCloud.Events.Exceptions.ValidationException”ValidationException
Section titled “ValidationException”class ValidationException(Exception)Exception raised for validation errors.
TrimbleCloud.Events.Exceptions.ConnectionClosedException
Section titled “TrimbleCloud.Events.Exceptions.ConnectionClosedException”ConnectionClosedException
Section titled “ConnectionClosedException”class ConnectionClosedException(Exception)Exception raised when a connection is closed unexpectedly.
to_json
Section titled “to_json”def to_json()Convert the exception to a JSON string.
Returns:
str- The JSON representation of the exception.
TrimbleCloud.Events.Exceptions.PublisherException
Section titled “TrimbleCloud.Events.Exceptions.PublisherException”PublisherException
Section titled “PublisherException”class PublisherException(Exception)Exception raised when there is an error in the publisher.
to_json
Section titled “to_json”def to_json()Converts the exception to a JSON string.
Returns:
str- The JSON representation of the exception.
TrimbleCloud.Events.Exceptions.WebSocketException
Section titled “TrimbleCloud.Events.Exceptions.WebSocketException”WebSocketException
Section titled “WebSocketException”class WebSocketException(Exception)Represents an exception that occurs in the WebSocket communication.
to_json
Section titled “to_json”def to_json()Converts the WebSocketException object to a JSON string.
Returns:
str- The JSON representation of the WebSocketException object.
TrimbleCloud.Events.Services.ConnectionHandler
Section titled “TrimbleCloud.Events.Services.ConnectionHandler”ConnectionHandler
Section titled “ConnectionHandler”class ConnectionHandler(threading.Thread)A Connection Handler manages all the old connections and close them after specified time
Arguments:
workflow(Workflow): client workflowack_wait_ms(int): time to wait before closing connection (Publisher)create_web_socket_client(function): function to create websocket clientswitch_connection(function): function to switch connectionendpoint(string): connection endpoint