stream_manager.streammanagerclient module

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

class stream_manager.streammanagerclient.StreamManagerClient(host='127.0.0.1', port=None, connect_timeout=3, request_timeout=60, logger=<Logger StreamManagerClient (WARNING)>)[source]

Bases: object

Creates a client for the Greengrass StreamManager. All parameters are optional.

Parameters
  • host – The host which StreamManager server is running on. Default is localhost.

  • port – The port which StreamManager server is running on. Default is found in environment variables.

  • connect_timeout – The timeout in seconds for connecting to the server. Default is 3 seconds.

  • request_timeout – The timeout in seconds for all operations. Default is 60 seconds.

  • logger – A logger to use for client logging. Default is Python’s builtin logger.

Raises

StreamManagerException and subtypes if authenticating to the server fails.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to connect to the server.

read_messages(stream_name: str, options: Optional[stream_manager.data.ReadMessagesOptions] = None)List[stream_manager.data.Message][source]

Read message(s) from a chosen stream with options. If no options are specified it will try to read 1 message from the stream.

Parameters
  • stream_name – The name of the stream to read from.

  • options

    (Optional) Options used when reading from the stream of type data.ReadMessagesOptions. Defaults are:

    • desired_start_sequence_number: 0,

    • min_message_count: 1,

    • max_message_count: 1,

    • read_timeout_millis: 0 # Where 0 here represents that the server will immediately return the messages

      # or an exception if there were not enough messages available.

    If desired_start_sequence_number is specified in the options and is less than the current beginning of the stream, returned messages will start at the beginning of the stream and not necessarily the desired_start_sequence_number.

Returns

List of at least 1 message.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

append_message(stream_name: str, data: bytes)int[source]

Append a message into the specified message stream. Returns the sequence number of the message if it was successfully appended.

Parameters
  • stream_name – The name of the stream to append to.

  • data – Bytes type data.

Returns

Sequence number that the message was assigned if it was appended.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

create_message_stream(definition: stream_manager.data.MessageStreamDefinition)None[source]

Create a message stream with a given definition.

Parameters

definitionMessageStreamDefinition definition object.

Returns

Nothing is returned if the request succeeds.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

delete_message_stream(stream_name: str)None[source]

Deletes a message stream based on its name. Nothing is returned if the request succeeds, a subtype of StreamManagerException will be raised if an error occurs.

Parameters

stream_name – The name of the stream to be deleted.

Returns

Nothing is returned if the request succeeds.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

update_message_stream(definition: stream_manager.data.MessageStreamDefinition)None[source]

Updates a message stream based on a given definition. Minimum version requirements: StreamManager server version 1.1 (or AWS IoT Greengrass Core 1.11.0)

Parameters

definition – class:MessageStreamDefinition definition object.

Returns

Nothing is returned if the request succeeds.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

list_streams()List[str][source]

List the streams in StreamManager. Returns a list of their names.

Returns

List of stream names.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

describe_message_stream(stream_name: str)stream_manager.data.MessageStreamInfo[source]

Describe a message stream to get metadata including the stream’s definition, size, and exporter statuses.

Parameters

stream_name – The name of the stream to describe.

Returns

MessageStreamInfo type containing the stream information.

Raises

StreamManagerException and subtypes based on the precise error.

Raises

asyncio.TimeoutError if the request times out.

Raises

ConnectionError if the client is unable to reconnect to the server.

close()[source]

Call to shutdown the client and close all existing connections. Once a client is closed it cannot be reused.

Raises

StreamManagerException and subtypes based on the precise error.