pub-sub-api-node-client icon indicating copy to clipboard operation
pub-sub-api-node-client copied to clipboard

Library does not handle subscriptions to `data/ChangeEvents`

Open eltoroit opened this issue 1 year ago • 1 comments

Although, I can subscribe to the generic CDC event data/ChangeEvents, when it receives the notification it's not able to handle it.

I am getting this error:

Connected to Pub/Sub API endpoint api.pubsub.salesforce.com:7443
Subscribe request sent for 100 events from /data/ChangeEvents...
Received 6 events, latest replay ID: 1762404
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error: 3 INVALID_ARGUMENT: Schema validation failed. The schema ID can't be blank. rpcId: 08e6cf95-ce52-4389-8e26-e902caee0c17
    at callErrorFromStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client.js:193:76)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client.js:161:32)
    at ServiceClientImpl.<anonymous> (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at file:///Users/aperez/Git%20Projects/current/ARC101/2024/grpc/node_modules/salesforce-pubsub-api-client/dist/client.js:1029:20
    at new Promise (<anonymous>)
    at #fetchEventSchemaFromIdWithClient (file:///Users/aperez/Git%20Projects/current/ARC101/2024/grpc/node_modules/salesforce-pubsub-api-client/dist/client.js:1028:12)
    at Object.callback (file:///Users/aperez/Git%20Projects/current/ARC101/2024/grpc/node_modules/salesforce-pubsub-api-client/dist/client.js:1012:76)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client.js:188:40)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /Users/aperez/Git Projects/current/ARC101/2024/grpc/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78 {
  code: 3,
  details: "Schema validation failed. The schema ID can't be blank. rpcId: 08e6cf95-ce52-4389-8e26-e902caee0c17",
  metadata: Metadata {
    internalRepr: Map(6) {
      'content-type' => [ 'application/grpc' ],
      'error-code' => [ 'sfdc.platform.eventbus.grpc.schema.validation.failed' ],
      'rpc-id' => [ '08e6cf95-ce52-4389-8e26-e902caee0c17' ],
      'type' => [ 'GetSchema' ],
      'date' => [ 'Fri, 31 May 2024 12:47:32 GMT' ],
      'x-envoy-upstream-service-time' => [ '62' ]
    },
    options: {}
  }
}

Node.js v20.12.2

I think problem is here https://github.com/pozil/pub-sub-api-node-client/blob/40de44d379929126d1f621d0a0652201ceeb7a38/src/client.js#L565 because the response does not have a schemaId.

eltoroit avatar May 31 '24 12:05 eltoroit

Hi @eltoroit, thanks for reporting this error. Unfortunately, this is is not something that I can address at the client level as I can't modify the schema validation logic from the gRPC library and Schema ID is mandatory according the proto file of the API.

In order to support data/ChangeEvents, we would either need:

  • a proto file update from the Salesforce product team to make schema ID optional (unlikely)
  • a schema ID to be sent from the server for those messages.

The reason why there's no schema ID on this channel is that it's a composite source that matches multiple schemas/objects. I had a similar issue with custom message channels: the schema ID wasn't mapped to a schema that we could retrieve because of its composite nature. However, we did have an ID so we could avoid the schema error and parse incoming events with some special logic.

I would open a bug on https://github.com/forcedotcom/pub-sub-api to request data/ChangeEvents schema ID support.

pozil avatar Jun 03 '24 08:06 pozil