public interface WebSocketClient extends TopologyElement
A connector is bound to its configuration specified
javax.websockets
WebSocket URI.
A single connector instance supports sinking at most one stream and sourcing at most one stream.
Sample use:
// assuming a properties file containing at least:
// ws.uri=ws://myWsServerHost/myService
String propsPath = <path to properties file>;
Properties properties = new Properties();
properties.load(Files.newBufferedReader(new File(propsPath).toPath()));
Topology t = ...;
Jsr356WebSocketClient wsclient = new SomeWebSocketClient(t, properties);
// send a stream's JsonObject tuples as JSON WebSocket text messages
TStream<JsonObject> s = ...;
wsclient.send(s);
// create a stream of JsonObject tuples from received JSON WebSocket text messages
TStream<JsonObject> r = wsclient.receive();
r.print();
Note, the WebSocket protocol differentiates between text/String and binary/byte messages. A receiver only receives the messages of the type that it requests.
Implementations are strongly encouraged to support construction from Properties with the following configuration parameters:
Modifier and Type | Method and Description |
---|---|
TStream<com.google.gson.JsonObject> |
receive()
Create a stream of JsonObject tuples from received JSON WebSocket text messages.
|
TStream<byte[]> |
receiveBytes()
Create a stream of byte[] tuples from received WebSocket binary messages.
|
TStream<java.lang.String> |
receiveString()
Create a stream of String tuples from received WebSocket text messages.
|
TSink<com.google.gson.JsonObject> |
send(TStream<com.google.gson.JsonObject> stream)
Send a stream's JsonObject tuples as JSON in a WebSocket text message.
|
TSink<byte[]> |
sendBytes(TStream<byte[]> stream)
Send a stream's byte[] tuples in a WebSocket binary message.
|
TSink<java.lang.String> |
sendString(TStream<java.lang.String> stream)
Send a stream's String tuples in a WebSocket text message.
|
topology
TSink<com.google.gson.JsonObject> send(TStream<com.google.gson.JsonObject> stream)
stream
- the streamTSink<java.lang.String> sendString(TStream<java.lang.String> stream)
stream
- the streamTSink<byte[]> sendBytes(TStream<byte[]> stream)
stream
- the streamTStream<com.google.gson.JsonObject> receive()
TStream<java.lang.String> receiveString()
Note, the WebSocket protocol differentiates between text/String and binary/byte messages. This method only receives messages sent as text.
TStream<byte[]> receiveBytes()
Note, the WebSocket protocol differentiates between text/String and binary/byte messages. This method only receives messages sent as bytes.
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641