examples-es icon indicating copy to clipboard operation
examples-es copied to clipboard

Request - Node client BiDi streaming example.

Open JoelBrenstrum opened this issue 1 year ago • 3 comments

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.

JoelBrenstrum avatar Oct 02 '23 02:10 JoelBrenstrum

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);
}

srikrsna-buf avatar Oct 02 '23 04:10 srikrsna-buf

Given this example, how would you control the connection from the client side? Specifically I would like to know how to:

  1. Close the connection
  2. Detect when the connection closes/when the server closes the connection
  3. Re-open the connection if the server closes it abruptly

nikoprotic avatar Mar 18 '24 21:03 nikoprotic

@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

srikrsna-buf avatar Mar 19 '24 19:03 srikrsna-buf