StreamClient

class oci.streaming.StreamClient(config, service_endpoint, **kwargs)

Use the Streaming API to produce and consume messages, create streams and stream pools, and manage related items. For more information, see [Streaming](/Content/Streaming/Concepts/streamingoverview.htm).

Methods

__init__(config, service_endpoint, **kwargs) Creates a new service client
consumer_commit(stream_id, cursor, **kwargs) Provides a mechanism to manually commit offsets, if not using commit-on-get consumer semantics.
consumer_heartbeat(stream_id, cursor, **kwargs) Allows long-running processes to extend the timeout on partitions reserved by a consumer instance.
create_cursor(stream_id, …) Creates a cursor.
create_group_cursor(stream_id, …) Creates a group-cursor.
get_group(stream_id, group_name, **kwargs) Returns the current state of a consumer group.
get_messages(stream_id, cursor, **kwargs) Returns messages from the specified stream using the specified cursor as the starting point for consumption.
put_messages(stream_id, …) Emits messages to a stream.
update_group(stream_id, group_name, …) Forcefully changes the current location of a group as a whole; reseting processing location of all consumers to a particular location in the stream.
__init__(config, service_endpoint, **kwargs)

Creates a new service client

Parameters:
  • config (dict) – Configuration keys and values as per SDK and Tool Configuration. The from_file() method can be used to load configuration from a file. Alternatively, a dict can be passed. You can validate_config the dict using validate_config()
  • service_endpoint (str) – The endpoint of the service to call using this client. For example https://iaas.us-ashburn-1.oraclecloud.com.
  • timeout (float or tuple(float, float)) – (optional) The connection and read timeouts for the client. The default values are connection timeout 10 seconds and read timeout 60 seconds. This keyword argument can be provided as a single float, in which case the value provided is used for both the read and connection timeouts, or as a tuple of two floats. If a tuple is provided then the first value is used as the connection timeout and the second value as the read timeout.
  • signer (AbstractBaseSigner) –

    (optional) The signer to use when signing requests made by the service client. The default is to use a Signer based on the values provided in the config parameter.

    One use case for this parameter is for Instance Principals authentication by passing an instance of InstancePrincipalsSecurityTokenSigner as the value for this keyword argument

  • retry_strategy (obj) –

    (optional) A retry strategy to apply to all calls made by this service client (i.e. at the client level). There is no retry strategy applied by default. Retry strategies can also be applied at the operation level by passing a retry_strategy keyword argument as part of calling the operation. Any value provided at the operation level will override whatever is specified at the client level.

    This should be one of the strategies available in the retry module. A convenience DEFAULT_RETRY_STRATEGY is also available. The specifics of the default retry strategy are described here.

  • circuit_breaker_strategy (obj) – (optional) A circuit breaker strategy to apply to all calls made by this service client (i.e. at the client level). This client will not have circuit breakers enabled by default, users can use their own circuit breaker strategy or the convenient DEFAULT_CIRCUIT_BREAKER_STRATEGY provided by the SDK to enable it. The specifics of circuit breaker strategy are described here.
  • circuit_breaker_callback (function) – (optional) Callback function to receive any exceptions triggerred by the circuit breaker.
  • client_level_realm_specific_endpoint_template_enabled (bool) – (optional) A boolean flag to indicate whether or not this client should be created with realm specific endpoint template enabled or disable. By default, this will be set as None.
  • allow_control_chars – (optional) allow_control_chars is a boolean to indicate whether or not this client should allow control characters in the response object. By default, the client will not allow control characters to be in the response object.
consumer_commit(stream_id, cursor, **kwargs)

Provides a mechanism to manually commit offsets, if not using commit-on-get consumer semantics. This commits offsets assicated with the provided cursor, extends the timeout on each of the affected partitions, and returns an updated cursor.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • cursor (str) – (required) The group-cursor representing the offsets of the group. This cursor is retrieved from the CreateGroupCursor API call.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type Cursor

Return type:

Response

Example:

Click here to see an example of how to use consumer_commit API.

consumer_heartbeat(stream_id, cursor, **kwargs)

Allows long-running processes to extend the timeout on partitions reserved by a consumer instance.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • cursor (str) – (required) The group-cursor representing the offsets of the group. This cursor is retrieved from the CreateGroupCursor API call.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type Cursor

Return type:

Response

Example:

Click here to see an example of how to use consumer_heartbeat API.

create_cursor(stream_id, create_cursor_details, **kwargs)

Creates a cursor. Cursors are used to consume a stream, starting from a specific point in the partition and going forward from there. You can create a cursor based on an offset, a time, the trim horizon, or the most recent message in the stream. As the oldest message inside the retention period boundary, using the trim horizon effectively lets you consume all messages in the stream. A cursor based on the most recent message allows consumption of only messages that are added to the stream after you create the cursor. Cursors expire five minutes after you receive them from the service.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • create_cursor_details (oci.streaming.models.CreateCursorDetails) – (required) The information used to create the cursor.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type Cursor

Return type:

Response

Example:

Click here to see an example of how to use create_cursor API.

create_group_cursor(stream_id, create_group_cursor_details, **kwargs)

Creates a group-cursor.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • create_group_cursor_details (oci.streaming.models.CreateGroupCursorDetails) – (required) The information used to create the cursor.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type Cursor

Return type:

Response

Example:

Click here to see an example of how to use create_group_cursor API.

get_group(stream_id, group_name, **kwargs)

Returns the current state of a consumer group.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • group_name (str) – (required) The name of the consumer group.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type Group

Return type:

Response

Example:

Click here to see an example of how to use get_group API.

get_messages(stream_id, cursor, **kwargs)

Returns messages from the specified stream using the specified cursor as the starting point for consumption. By default, the number of messages returned is undefined, but the service returns as many as possible. To get messages, you must first obtain a cursor using the create_cursor() operation. In the response, retrieve the value of the ‘opc-next-cursor’ header to pass as a parameter to get the next batch of messages in the stream.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • cursor (str) – (required) The cursor used to consume the stream.
  • limit (int) – (optional) The maximum number of messages to return. You can specify any value up to 10000. By default, the service returns as many messages as possible. Consider your average message size to help avoid exceeding throughput on the stream.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type list of Message

Return type:

Response

Example:

Click here to see an example of how to use get_messages API.

put_messages(stream_id, put_messages_details, **kwargs)

Emits messages to a stream. There’s no limit to the number of messages in a request, but the total size of a message or request must be 1 MiB or less. The service calculates the partition ID from the message key and stores messages that share a key on the same partition. If a message does not contain a key or if the key is null, the service generates a message key for you. The partition ID cannot be passed as a parameter.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • put_messages_details (oci.streaming.models.PutMessagesDetails) – (required) Array of messages to put into the stream.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation will not retry by default, users can also use the convenient DEFAULT_RETRY_STRATEGY provided by the SDK to enable retries for it. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type PutMessagesResult

Return type:

Response

Example:

Click here to see an example of how to use put_messages API.

update_group(stream_id, group_name, update_group_details, **kwargs)

Forcefully changes the current location of a group as a whole; reseting processing location of all consumers to a particular location in the stream.

Parameters:
  • stream_id (str) – (required) The OCID of the stream.
  • group_name (str) – (required) The name of the consumer group.
  • update_group_details (oci.streaming.models.UpdateGroupDetails) – (required) The information used to modify the group.
  • opc_request_id (str) – (optional) The unique Oracle-assigned identifier for the request. If you need to contact Oracle about a particular request, please provide the request ID.
  • retry_strategy (obj) –

    (optional) A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.

    This should be one of the strategies available in the retry module. This operation uses DEFAULT_RETRY_STRATEGY as default if no retry strategy is provided. The specifics of the default retry strategy are described here.

    To have this operation explicitly not perform any retries, pass an instance of NoneRetryStrategy.

  • allow_control_chars (bool) – (optional) allow_control_chars is a boolean to indicate whether or not this request should allow control characters in the response object. By default, the response will not allow control characters in strings
Returns:

A Response object with data of type None

Return type:

Response

Example:

Click here to see an example of how to use update_group API.