メインコンテンツへスキップ
X API SDK 向けの堅牢なストリーミングユーティリティ。 このモジュールは、自動再接続、指数バックオフ、包括的なエラーハンドリングを備えたストリーミング接続の管理機能を提供します。Client は接続管理を気にせずにストリーミングエンドポイントを利用でき、復旧はすべて SDK が自動的に処理します。

class xdk.streaming.StreamConfig

リトライ動作を伴うストリーミング接続の設定。

パラメータ

path.max_retries
int
デフォルト:"10"
path.initial_backoff
float
デフォルト:"1.0"
path.max_backoff
float
デフォルト:"64.0"
path.backoff_multiplier
float
デフォルト:"2.0"
path.jitter
bool
デフォルト:"True"
path.timeout
float or None
デフォルト:"None"
path.chunk_size
int
デフォルト:"1024"
path.on_connect
Callable[[], None] or None
デフォルト:"None"
path.on_disconnect
Callable[[Exception or None], None] or None
デフォルト:"None"
path.on_reconnect
Callable[[int, float], None] or None
デフォルト:"None"
path.on_error
Callable[[[StreamError

__init__

パラメータ

path.max_retries
int
デフォルト:"10"
path.initial_backoff
float
デフォルト:"1.0"
path.max_backoff
float
デフォルト:"64.0"
path.backoff_multiplier
float
デフォルト:"2.0"
path.jitter
bool
デフォルト:"True"
path.timeout
float or None
デフォルト:"None"
path.chunk_size
int
デフォルト:"1024"
path.on_connect
Callable[[], None] or None
デフォルト:"None"
path.on_disconnect
Callable[[Exception or None], None] or None
デフォルト:"None"
path.on_reconnect
Callable[[int, float], None] or None
デフォルト:"None"
path.on_error
Callable[[[StreamError

on_error : Callable[[[StreamError]

exception xdk.streaming.StreamError

分類情報を伴うストリーミングエラーが発生したときに送出される例外です。

パラメータ

path.message
str
path.error_type
StreamErrorType

__init__

パラメータ

path.message
str
path.error_type
StreamErrorType

class xdk.streaming.StreamErrorType

再試行判断に用いるストリーミングエラーの分類。

パラメータ

path.value
Any

class xdk.streaming.StreamState

ストリーミング接続の内部状態を表します。

パラメーター

path.retry_count
int
デフォルト:"0"
path.current_backoff
float
デフォルト:"1.0"
path.is_connected
bool
デフォルト:"False"
path.total_items_received
int
デフォルト:"0"
path.last_error
StreamError

__init__

パラメータ

path.retry_count
int
デフォルト:"0"
path.current_backoff
float
デフォルト:"1.0"
path.is_connected
bool
デフォルト:"False"
path.total_items_received
int
デフォルト:"0"
path.last_error
StreamError

last_error : [StreamError]

xdk.streaming.stream_with_retry

自動再接続と指数バックオフを用いて、エンドポイントからデータをストリーミングします。 この関数は、以下を含むすべての接続管理を行います:
  • 切断時の自動再接続
  • リトライ待機時間に対するジッター付き指数バックオフ
  • エラーを再試行可能なものと致命的なものに分類
  • 接続状態を監視するためのライフサイクルコールバック

パラメーター

path.session
Session
HTTP 呼び出しに使用する requests の Session オブジェクト。
path.method
str
HTTP メソッド(通常は「get」)。
path.url
str
ストリーミング元となる完全な URL。
path.config
StreamConfig
リトライおよびコールバック設定を含む StreamConfig。