Skip to content

Websocket

Spout for Websocket

Bases: Spout

__init__(output, state, **kwargs)

Initialize the Websocket class.

Parameters:

Name Type Description Default
output StreamingOutput

An instance of the StreamingOutput class for saving the data.

required
state State

An instance of the State class for maintaining the state.

required
**kwargs

Additional keyword arguments.

{}

Using geniusrise to invoke via command line

genius Websocket rise \
    streaming \
        --output_kafka_topic websocket_test \
        --output_kafka_cluster_connection_string localhost:9094 \
    none \
    listen \
        --args host=localhost port=8765

Using geniusrise to invoke via YAML file

version: "1"
spouts:
    my_websocket_spout:
        name: "Websocket"
        method: "listen"
        args:
            host: "localhost"
            port: 8765
        output:
            type: "streaming"
            args:
                output_topic: "websocket_test"
                kafka_servers: "localhost:9094"

__listen(host, port) async

Start listening for data from the WebSocket server.

listen(host='localhost', port=8765)

📖 Start the WebSocket server.

Parameters:

Name Type Description Default
host str

The WebSocket server host. Defaults to "localhost".

'localhost'
port int

The WebSocket server port. Defaults to 8765.

8765

Raises:

Type Description
Exception

If unable to start the WebSocket server.

receive_message(websocket, path) async

Receive a message from a WebSocket client and save it along with metadata.

Parameters:

Name Type Description Default
websocket

WebSocket client connection.

required
path

WebSocket path.

required