Sync Styx Client
SyncStyxClient(styx_coordinator_adr, styx_coordinator_port, kafka_url)
¶
Bases: BaseStyxClient
Synchronous client for interacting with a Styx deployment.
This client handles dataflow submission and event communication with Styx via Kafka and TCP. It manages metadata and result consumption threads, handles serialization, and tracks outstanding futures.
Initializes a synchronous Styx client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
styx_coordinator_adr
|
str
|
Address of the Styx coordinator. |
required |
styx_coordinator_port
|
int
|
Port of the Styx coordinator. |
required |
kafka_url
|
str
|
Kafka bootstrap server URL. |
required |
close()
¶
Closes the client, terminating consumers and flushing producers.
flush()
¶
Flushes the Kafka producer buffer to ensure all messages are sent.
Raises:
Type | Description |
---|---|
AssertionError
|
If flushing fails to empty the queue. |
get_operator_partition(key, operator)
¶
Returns the partition for a given key/operator pair.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Any
|
Partitioning key. |
required |
operator
|
BaseOperator
|
Operator to route the key to. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Partition number for the given key. |
open(consume=True)
¶
Opens the Kafka producer and starts consumer threads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
consume
|
bool
|
If True, also starts the results consumer. |
True
|
send_event(operator, key, function, params=tuple(), serializer=Serializer.MSGPACK)
¶
Sends a single event to an operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
BaseOperator
|
Target operator. |
required |
key
|
Any
|
Partitioning key for the event. |
required |
function
|
Type | str
|
Function or method to invoke. |
required |
params
|
tuple
|
Parameters to the function. |
tuple()
|
serializer
|
Serializer
|
Serialization strategy. |
MSGPACK
|
Returns:
Name | Type | Description |
---|---|---|
StyxFuture |
StyxFuture
|
Future associated with the event. |
submit_dataflow(stateflow_graph, external_modules=None)
¶
Submits a dataflow graph to the Styx coordinator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stateflow_graph
|
StateflowGraph
|
The graph to submit. |
required |
external_modules
|
tuple
|
Extra modules needed by operators. |
None
|