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:
objectCreates 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
StreamManagerExceptionand subtypes if authenticating to the server fails.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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.
- read_timeout_millis: 0
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
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
definition –
MessageStreamDefinitiondefinition object.- Returns
Nothing is returned if the request succeeds.
- Raises
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
StreamManagerExceptionwill 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
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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:
MessageStreamDefinitiondefinition object.- Returns
Nothing is returned if the request succeeds.
- Raises
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
MessageStreamInfotype containing the stream information.- Raises
StreamManagerExceptionand subtypes based on the precise error.- Raises
asyncio.TimeoutErrorif the request times out.- Raises
ConnectionErrorif 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
StreamManagerExceptionand subtypes based on the precise error.