You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -15,7 +15,8 @@ See the [official Pub/Sub API repo](https://github.com/developerforce/pub-sub-ap
15
15
-[Logging](#logging)
16
16
-[Quick Start Example](#quick-start-example)
17
17
-[Other Examples](#other-examples)
18
-
-[Publish a platform event](#publish-a-platform-event)
18
+
-[Publish a single platform event](#publish-a-single-platform-event)
19
+
-[Publish a batch of platform events](#publish-a-batch-of-platform-events)
19
20
-[Subscribe with a replay ID](#subscribe-with-a-replay-id)
20
21
-[Subscribe to past events in retention window](#subscribe-to-past-events-in-retention-window)
21
22
-[Subscribe using a managed subscription](#subscribe-using-a-managed-subscription)
@@ -24,6 +25,7 @@ See the [official Pub/Sub API repo](https://github.com/developerforce/pub-sub-ap
24
25
-[Common Issues](#common-issues)
25
26
-[Reference](#reference)
26
27
-[PubSubApiClient](#pubsubapiclient)
28
+
-[PublishCallback](#publishcallback)
27
29
-[SubscribeCallback](#subscribecallback)
28
30
-[SubscriptionInfo](#subscriptioninfo)
29
31
-[EventParseError](#eventparseerror)
@@ -44,7 +46,7 @@ In v4 and earlier versions of this client:
44
46
In v5:
45
47
46
48
- you pass your configuration with an object in the client constructor. The `.env` file is no longer a requirement, you are free to store your configuration where you want.
47
-
- you connect with a unique `connect()` method.
49
+
- you connect with a unique [`connect()`](#async-connect--promisevoid) method.
48
50
49
51
### Event handling
50
52
@@ -206,34 +208,38 @@ Here's an example that will get you started quickly. It listens to up to 3 accou
/* Convert BigInt values into strings and keep other types unchanged */
226
+
typeof value === 'bigint'
227
+
?value.toString()
228
+
: value,
229
+
2
230
+
)
231
+
);
232
+
break;
233
+
case'lastEvent':
234
+
// Last event received
235
+
console.log(
236
+
`${subscription.topicName} - Reached last of ${subscription.requestedEventCount} requested event on channel. Closing connection.`
237
+
);
238
+
break;
239
+
case'end':
240
+
// Client closed the connection
241
+
console.log('Client shut down gracefully.');
242
+
break;
237
243
}
238
244
};
239
245
@@ -345,9 +351,12 @@ Here's an example that will get you started quickly. It listens to up to 3 accou
345
351
346
352
## Other Examples
347
353
348
-
### Publish a platform event
354
+
### Publish a single platform event
349
355
350
-
Publish a `Sample__e` Platform Event with a `Message__c` field:
356
+
> [!NOTE]
357
+
> For best performances, use `publishBatch` when publishing event batches.
358
+
359
+
Publish a single `Sample__e` platform events with a `Message__c` field using [publish](#async-publishtopicname-payload-correlationkey--promisepublishresult):
Subscribe to 5 account change events starting from a replay ID:
@@ -416,7 +454,7 @@ When working with high volumes of events you can control the incoming flow of ev
416
454
This is the overall process:
417
455
418
456
1. Pass a number of requested events in your subscribe call.
419
-
1. Handle the `lastevent` callback type from subscribe callback to detect the end of the event batch.
457
+
1. Handle the `lastevent`[callback type](#subscribecallback) from subscribe callback to detect the end of the event batch.
420
458
1. Subscribe to an additional batch of events with `client.requestAdditionalEvents(...)`. If you don't request additional events at this point, the gRPC subscription will close automatically (default Pub/Sub API behavior).
421
459
422
460
The code below illustrate how you can achieve event flow control:
|`publishResponse`| [PublishResponse](#publishresponse) | Client received a publish response. The attached data is the publish confirmation for a batch of events. |
684
+
|`error`| Object | Signals an event publishing error or a gRPC stream error. |
685
+
|`grpcKeepalive`|`{ schemaId: string, rpcId: string }`| Server publishes this gRPC keep alive message every 270 seconds (or less) if there are no events. |
686
+
|`grpcStatus`| Object | Misc gRPC stream status information. |
|`results`|`{ replayId: string, correlationKey: string }[]`| Event publish confirmations. Each confirmation contains the replay ID and a correlation key. |
695
+
615
696
### SubscribeCallback
616
697
617
698
Callback functionthat lets you process incoming Pub/Sub API events while keeping track of the topic name and the volume of events requested/received.
0 commit comments