examples-es
examples-es copied to clipboard
Request - Node client BiDi streaming example.
I am struggling to get a node client to work with external gRPC server (Salesforce Pub/Sub) for BiDiStreaming. Unary requests are working fine. I can create the initial stream but it is closed as soon as I attempt to read it.
My code is very similar to this example https://www.supaglue.com/blog/how-to-build-a-real-time-cdc-event-integration-with-your-customers-salesforce.
I've gone through all the examples and have yet to find one where the client consumes BiDiStreaming. I would appreciate it if the node client example could consume the stream.
Hey! We'll get them added thank you for opening the issue. In the meantime here's a small sample:
import {
createGrpcTransport,
} from "@connectrpc/connect-node";
import {ElizaService} from "gen/...";
const transport = createGrpcTransport({
baseUrl: "https://demo.connectrpc.com",
httpVersion: "2",
});
const client = createPromiseClient(ElizaService, transport);
const res = client.converse(
(async function* () {
yield { sentence: "Hey!" };
})()
);
for await (const next of res) {
console.log(next.sentence);
}
Given this example, how would you control the connection from the client side? Specifically I would like to know how to:
- Close the connection
- Detect when the connection closes/when the server closes the connection
- Re-open the connection if the server closes it abruptly
@nikoprotic You can use the WritableIterable
to have more control on the client side, here's an example usage from the connect repo: https://github.com/connectrpc/connect-es/blob/06234f16d9e06a140f953e0115952a7324878897/packages/connect-node-test/src/node-readme.spec.ts#L265-L282