Skip to content

TrimbleCloud.Events

class Session()

Represents a session for interacting with the Trimble Cloud Events service.

Arguments:

  • endpoint str - The endpoint URL of the service.
  • client_id str - The client ID for authentication.
  • client_secret str - The client secret for authentication.
  • tid_scope str, optional - The TID scope for authentication. Defaults to None.
  • auth_url str - The authentication URL.
  • enable_batch bool, optional - Enable batch processing. Defaults to False.
  • batch_buffer_size int, optional - The size of the batch buffer. Required if enable_batch is True.
  • batch_buffer_ms int, optional - The time in milliseconds to wait before sending a batch. Required if enable_batch is True.
  • batch_expiry_ms int, optional - The time in milliseconds after which a batch expires. Required if enable_batch is True.
  • workflow Workflow - The workflow type (PUBLISHER or CONSUMER).
  • call_back callable - The callback function to handle events.
  • retry_count int - The number of times to retry connection.
  • ack_wait_ms int, optional - The time in milliseconds to wait for acknowledgement. Required for PUBLISHER workflow with enable_batch is True or CONSUMER workflow.
  • ack_retry int, optional - The number of times to retry acknowledgement. Required for PUBLISHER workflow with enable_batch is True or CONSUMER workflow.
  • client_acknowledge bool, optional - Enable client acknowledgement. Required for CONSUMER workflow.
  • enable_metrics bool - Enable metrics recording.
  • datadog_api_key str, optional - The API key for Datadog integration. Required if enable_metrics is True.
  • datadog_application_key str, optional - The application key for Datadog integration. Required if enable_metrics is True.
  • datadog_metrics_tags dict, optional - The tags for Datadog metrics. Required if enable_metrics is True.
  • metric_recorder str, 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:

  • url str - The endpoint URL of the service.
  • active bool - Indicates if the session is active.
  • connection_status Status - The connection status of the session.

@property
def url()

Returns the endpoint URL for the session.

Returns:

The endpoint URL.

@property
def active()

Check if the session is active.

Returns:

  • bool - True if the session is active, False otherwise.

@property
def 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:

  • batch Batch - 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.

def publish_message(event)

Publishes an event message.

Arguments:

  • event Event - The event object to be published.

Raises:

  • PublisherException - If batching is disabled.

def poll(event)

Polls for an event from the server.

Arguments:

  • event Event - 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

def acknowledge(acknowledgment_id)

Method to explicitly acknowledge the receipt of a message with the given acknowledgment ID.

Arguments:

  • acknowledgment_id str - 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.

def on_message(message, websocket)

Handles incoming messages from the websocket.

Arguments:

  • message str - The message received from the websocket.
  • websocket - The websocket object.

Returns:

None

def on_error(error)

Handles the error response received from the server.

Arguments:

  • error Exception - The error response received from the server.

Returns:

None

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 name
  • level (int): Logging level, e.g. logging.INFO
  • format_string (str): Log message format

def client(**kwargs)

Create a low-level service client by name using the default session.

See :py:meth:boto3.session.Session.client.

class Event()

Represents an event in the Trimble Cloud Events system.

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_key str - The product key associated with the event.
  • namespace str - The namespace of the event.
  • event str - The name of the event.
  • event_version str - The version of the event.
  • client_id str - The client ID associated with the event.
  • visibility_timeout int, optional - The visibility timeout of the event in milliseconds. Defaults to None.
  • additional_fields dict, optional - Additional fields associated with the event. Defaults to None.

@property
def productKey()

The read-only product_key.

@property
def namespace()

The read-only namespace.

@property
def event()

The read-only event.

@property
def eventVersion()

The read-only event_version.

@property
def clientId()

The read-only client_id.

class ConsumeEvent(Event)

Represents a consumed event.

Inherits from the base Event class and provides additional functionality for consuming events.

Attributes:

  • product_key str - The product key associated with the event.

  • namespace str - The namespace of the event.

  • event str - The event name.

  • event_version str - The version of the event.

  • client_id str - The client ID associated with the event.

  • visibility_timeout int - A period of time to prevent consumer from receiving and processing the message (Minimum value = 3 seconds & Maximum value = 60 minutes)

  • additional_fields dict - Additional fields associated with the event.

    Properties:

  • creation_time float - 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.

@property
def creation_time()

The read-only creation_time.

Returns:

float: The creation time of the event.

def to_dict()

Converts the ConsumeEvent object to a dictionary.

Returns:

dict: A dictionary representation of the ConsumeEvent object.

def to_json()

Converts the ConsumeEvent object to a JSON string.

Returns:

str: A JSON string representation of the ConsumeEvent object.

class Response()

Represents a response object.

Attributes:

  • response_type str - The response type.
  • acknowledgment_id str - The acknowledgment ID.
  • consumer_group_id str - The consumer group ID.
  • error_message str - The error message.
  • response_messages list - The list of response messages.
  • consumer_request Namespace - The consumer request.

def get_kafka_response_list(response_messages)

Get the list of Kafka responses.

Arguments:

  • response_messages list - The list of response messages.

Returns:

  • list - The list of Kafka responses.

def __init__(message)

Initialize a Response object.

Arguments:

  • message str - The response message.

@property
def response_type()

Get the response type.

Returns:

  • str - The response type.

@property
def acknowledgment_id()

Get the acknowledgment ID.

Returns:

  • str - The acknowledgment ID.

@property
def consumer_group_id()

Get the consumer group ID.

Returns:

  • str - The consumer group ID.

@property
def error_message()

Get the error message.

Returns:

  • str - The error message.

@property
def response_messages()

Get the list of response messages.

Returns:

  • list - The list of response messages.

@property
def consumer_request()

Get the consumer request.

Returns:

  • Namespace - The consumer request.

def to_dict()

Convert the Response object to a dictionary.

Returns:

  • dict - The Response object as a dictionary.

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”

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.

class PublishEvent(Event)

Represents a publish event.

Inherits from the base Event class and provides additional functionality for publishing events.

Arguments:

  • product_key str - The product key.
  • namespace str - The namespace.
  • event str - The event.
  • event_version str - The event version.
  • client_id str - The client ID.
  • entity_id str - The entity ID.
  • payload dict - The payload.

Attributes:

  • connId str - The connection ID.
  • id str - The ID.
  • topicName str - The topic name.
  • feedback str - The feedback.

@property
def entityId()

The read-only entity_id.

@property
def payload()

The read-only payload.

def to_dict()

Convert the PublishEvent object to a dictionary.

Returns:

  • dict - The PublishEvent object as a dictionary.

@classmethod
def from_response(response_message)

Create a PublishEvent object from a response message.

Arguments:

  • response_message str - The response message.

Returns:

  • PublishEvent - The PublishEvent object.

class KafkaResponse()

Represents a response from Kafka.

@property
def acknowledgment_id()

The read-only acknowledgment_id.

@property
def entity_id()

The read-only entity_id.

@property
def message()

The read-only message.

class EventsBatch()

@property
def creation_time()

The read-only creation_time.

class Workflow(enum.Enum)

Represents the type of workflow.

Attributes:

  • PUBLISHER - The workflow is a publisher.
  • CONSUMER - The workflow is a consumer.

class BatchAck()

def __init__(batch_id)

Initializes a new instance of the BatchAck class.

Arguments:

  • batch_id str - The ID of the batch.

@property
def type()

Gets the read-only type.

Returns:

  • str - The type.

@property
def batch_id()

Gets the read-only batch ID.

Returns:

  • str - The batch ID.

def to_json()

Converts the BatchAck object to a JSON string.

Returns:

  • str - The JSON representation of the BatchAck object.

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”

class ConsumerException(Exception)

Exception raised when there is an error in the consumer.

TrimbleCloud.Events.Exceptions.ValidationException

Section titled “TrimbleCloud.Events.Exceptions.ValidationException”

class ValidationException(Exception)

Exception raised for validation errors.

TrimbleCloud.Events.Exceptions.ConnectionClosedException

Section titled “TrimbleCloud.Events.Exceptions.ConnectionClosedException”

class ConnectionClosedException(Exception)

Exception raised when a connection is closed unexpectedly.

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”

class PublisherException(Exception)

Exception raised when there is an error in the publisher.

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”

class WebSocketException(Exception)

Represents an exception that occurs in the WebSocket communication.

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”

class ConnectionHandler(threading.Thread)

A Connection Handler manages all the old connections and close them after specified time

Arguments:

  • workflow (Workflow): client workflow
  • ack_wait_ms (int): time to wait before closing connection (Publisher)
  • create_web_socket_client (function): function to create websocket client
  • switch_connection (function): function to switch connection
  • endpoint (string): connection endpoint