Subscribe to wire
Error handling is omitted from example code for brevity.
api
The WireAPI.SubscribeWire API enables clients to subscribe to a wire.
cli
Use the wire
command.
./volt wire --help
Subscribe to a wire using the cli wire
command along with the -s
or --subscribe
switch:
./volt wire <wire id> -s
All wire data will be written to STDOUT. This enables flows such as:
./volt wire @demo-wire -s | wire-data.log
fusebox
Navigate to the wire in the resource explorer and use the ‘subscribe’ button on the bottom panel, which contains a ‘headphones’ icon.
javascript
Use the SubscribeWire API, the callback will be called every time new data arrives.
grpc
import grpc from "@grpc/grpc-js";import { VoltClient } from "@tdxvolt/volt-client-grpc";
const client = new VoltClient(grpc);
const configPath = "./volt.config.json";
client .initialise(configPath) .then(() => { return new Promise((resolve, reject) => { const sub = client.SubscribeWire({ wire_id: "@wire-demo" });
sub.on("error", (err) => { reject(err); });
sub.on("data", (response) => { console.log(Buffer.from(response.chunk, "base64").toString()); });
sub.on("end", () => { resolve(); }); }); }) .catch((err) => { console.error("failure in subscribe-wire [%s]", err.message); });
web
const sub = client.SubscribeWire({ wireId }); sub.on("error", (err) => { console.error(err); });
sub.on("data", (response) => { console.log(atob(response.chunk)); });
sub.on("end", () => { console.log("subscription ended"); });
C++
examples coming soon...