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
Copy file name to clipboardExpand all lines: README.md
+13-5
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
-[About Pub/Sub API](#about-pubsub-api)
4
4
-[gRPC](#grpc)
5
5
-[Documentation and Blog Posts](#documentation-and-blog-post)
6
-
-[Code Samples](#code-samples)
6
+
-[Code Samples](#code-samples-from-salesforce)
7
7
8
8
## About Pub/Sub API
9
9
Welcome to Pub/Sub API! Pub/Sub API provides a single interface for publishing and subscribing to platform events, including real-time event monitoring events, and change data capture events. Based on [gRPC](https://grpc.io/docs/what-is-grpc/introduction/) and HTTP/2, Pub/Sub API enables efficient delivery of binary event messages in the Apache Avro format.
@@ -23,24 +23,32 @@ officially supported languages have well-supported Avro libraries:
-[Pub/Sub API Developer Guide](https://developer.salesforce.com/docs/platform/pub-sub-api/overview)
36
36
-[Salesforce Architects Blog Post](https://medium.com/salesforce-architects/announcing-pub-sub-api-generally-available-3980c9eaf0b7)
37
37
-[Introducing the New gRPC-based Pub Sub API YouTube Developer Quick Takes](https://youtu.be/g9P87_loVVA)
38
38
39
-
## Code Samples
39
+
## Code Samples from Salesforce
40
+
Salesforce provides these samples for demonstration purposes. They aren't meant to be used in production code. Before you use these samples in production, make sure you perform thorough functional and performance testing.
41
+
-[Java Quick Start in the Developer Guide](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/qs-java-quick-start.html)
40
42
-[Python Quick Start in the Developer Guide](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/qs-python-quick-start.html)
41
43
-[Python Code Examples](python/)
42
44
-[Go Code Examples](go/)
43
45
-[Java Code Examples](java/)
46
+
47
+
## Code Samples from the Developer Community
48
+
These examples are developed by the community. They aren't supported by Salesforce. Use at your own discretion.
-[Ruby Pub/Sub API Example](https://github.com/RenoFi/salesforce-pub-sub-rb)
53
+
54
+
If you have a code sample for Pub/Sub API that you would like to add a link to in this section, submit a PR with the modified readme page. We don't guarantee that we can link to all samples. Priority will be given to samples implemented in a programming language that is not represented in this repository's samples.
Copy file name to clipboardExpand all lines: java/README.md
+20-12
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Pub/Sub API Java Examples
2
2
3
3
## Overview
4
-
This directory contains some simple Java Examples that can be used with the Pub/Sub API. These examples range from generic Publish and Subscribe, processing CustomEventHeaders in change events and also a specific example of updating the Salesforce Account standard object. It is important to note that these examples are not performance tested nor are they production ready. They are meant to be used as a learning resource or a starting point to understand the flows of each of the Remote Procedure Calls (RPCs) of Pub/Sub API. There are some limitations to these examples as well mentioned below.
4
+
This directory contains some Java examples that can be used with the Pub/Sub API. These examples range from generic Publish, Subscribe, ManagedSubscribe (beta), processing CustomEventHeaders in change events, and a specific example of updating the Salesforce Account standard object. It is important to note that these examples are not performance tested nor are they production ready. They are meant to be used as a learning resource or a starting point to understand the flows of each of the Remote Procedure Calls (RPCs) of Pub/Sub API. There are some limitations to these examples as well mentioned below.
5
5
6
6
## Project Structure
7
7
In the `src/main` directory of the project, you will find several sub-directories as follows:
@@ -20,14 +20,14 @@ In the `src/main` directory of the project, you will find several sub-directorie
20
20
3. Run `mvn clean install` from the `java` directory to build the project and generate required sources from the proto file.
21
21
4. The `arguments.yaml` file in the `src/main/resources` sub-directory contains a list of required and optional configurations needed to run the examples. The file contains detailed comments on how to set the configurations.
22
22
5. Get the username, password, and login URL of the Salesforce org you wish to use.
23
-
6. For the examples in `genericpubsub` package, a custom **_CarMaintenance_**[platform event](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm) has to be created in the Salesforce org. Ensure your CarMaintenance platform event matches the following structure:
23
+
6. For the examples in `genericpubsub` package, a custom **_Order Event_**[platform event](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm) has to be created in the Salesforce org. Ensure your `Order Event` platform event matches the following structure:
24
24
- Standard Fields
25
-
- Label: `CarMaintenance`
26
-
- Plural Label: `CarMaintenances`
25
+
- Label: `Order Event`
26
+
- Plural Label: `Order Events`
27
27
- Custom Fields
28
-
-`Cost` (Number)
29
-
-`Mileage` (Number)
30
-
-`WorkDescription` (Text, 200)
28
+
-`Order Number` (Text, 18)
29
+
-`City` (Text, 50)
30
+
-`Amount` (Number, (16,2))
31
31
7. For the examples in the `accountupdateapp` package, another custom **_NewAccount_**[platform event](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm) has to be created in the Salesforce org. [More info here](src/main/java/accountupdateapp/README.md).
32
32
33
33
### Execution
@@ -37,14 +37,20 @@ In the `src/main` directory of the project, you will find several sub-directorie
37
37
*`PUBSUB_PORT`: Specify the Pub/Sub API port to be used (usually 7443).
38
38
*`LOGIN_URL`: Specify the login url of the Salesforce org being used to run the examples.
39
39
*`USERNAME` & `PASSWORD`: For authentication via username and password, you will need to specify the username and password of the Salesforce org.
40
-
*`ACCESS_TOKEN` & `TENANT_ID`: For authentication via session token an tenant ID, you will need to specify the sessionToken and tenant ID of the Salesforce org.
40
+
*`ACCESS_TOKEN` & `TENANT_ID`: For authentication via session token and tenant ID, you will need to specify the sessionToken and tenant ID of the Salesforce org.
41
+
* When using managed event subscriptions (beta), one of these configurations is required.
42
+
*`MANAGED_SUB_DEVELOPER_NAME`: Specify the developer name of ManagedEventSubscription. This parameter is used in ManagedSubscribe.java.
43
+
*`MANAGED_SUB_ID`: Specify the ID of the ManagedEventSubscription Tooling API record. This parameter is used in ManagedSubscribe.java.
44
+
41
45
2. Optional Parameters:
42
46
*`TOPIC`: Specify the topic for which you wish to publish/subscribe.
43
47
*`NUMBER_OF_EVENTS_TO_PUBLISH`: Specify the number of events to publish while using the PublishStream RPC.
44
-
*`NUMBER_OF_EVENTS_TO_SUBSCRIBE`: Specify the number of events to subscribe while using the Subscribe RPC.
48
+
*`SINGLE_PUBLISH_REQUEST`: Specify if you want to publish the events in a single or multiple PublishRequests.
49
+
*`NUMBER_OF_EVENTS_IN_FETCHREQUEST`: Specify the number of events that the Subscribe RPC requests from the server in each FetchRequest. The example fetches at most 5 events in each Subscribe request. If you pass in more than 5, it sends multiple Subscribe requests with at most 5 events requested in FetchRequest each. For more information about requesting events, see [Pull Subscription and Flow Control](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/flow-control.html) in the Pub/Sub API documentation.
50
+
*`PROCESS_CHANGE_EVENT_HEADER_FIELDS`: Specify whether the Subscribe or ManagedSubscribe client should process the change data capture event bitmap fields in `ChangeEventHeader`. In this sample, only the `changedFields` field is expanded. To expand the `diffFields` and `nulledFields` header fields, modify the sample code. See [Event Deserialization Considerations](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/event-deserialization-considerations.html).
45
51
*`REPLAY_PRESET`: Specify the ReplayPreset for subscribe examples.
46
52
* If a subscription has to be started using the CUSTOM replay preset, the `REPLAY_ID` parameter is mandatory.
47
-
* The `REPLAY_ID`has to be specified in the following format: `[<byte_values_separated_by_commas>]`. Please enter the values as is within the square brackets and without any quotes.
53
+
* The `REPLAY_ID`is a byte array and must be specified in this format: `[<byte_values_separated_by_commas>]`. Please enter the values as is within the square brackets and without any quotes.
48
54
* Example: `[0, 1, 2, 3, 4, -5, 6, 7, -8]`
49
55
50
56
2. After setting up the configurations, any example can be executed using the `./run.sh` file available at the parent directory.
@@ -53,10 +59,12 @@ In the `src/main` directory of the project, you will find several sub-directorie
53
59
54
60
## Implementation
55
61
- This repo can be used as a reference point for clients looking to create a Java app to integrate with Pub/Sub API. Note that the project structure and the examples included in this repo are intended for demo purposes only and clients are free to implement their own Java apps in any way they see fit.
56
-
- The Subscribe RPC examples demonstrates a basic flow control strategy where a new `fetchRequest` is sent only after the requested number of events in the previous `fetchRequest(s)` are received. Custom flow control strategies can be implemented as needed. More info on flow control available [here](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/flow-control.html).
62
+
- The Generic Subscribe and ManagedSubscribe (beta) RPC examples create a long-lived subscription. After all requested events are received, Subscribe sends a new `FetchRequest` and ManagedSubscribe sends a new `ManagedFetchRequest` to keep the subscription alive and the client listening to new events.
63
+
- The Generic Subscribe and ManagedSubscribe (beta) RPC examples demonstrate a basic flow control strategy where a new `FetchRequest` or `ManagedFetchRequest` is sent only after the requested number of events in the previous requests are received. The ManagedSubscribe RPC example also shows how to commit a Replay ID by sending commit requests. Custom flow control strategies can be implemented as needed. More info on flow control available [here](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/flow-control.html).
64
+
- The Generic Subscribe RPC example demonstrates error handling. After an exception occurs, it attempts to resubscribe after the last received event by implementing Binary Exponential Backoff. The example processes events and sends the retry requests asynchronously. If the error is an invalid replay ID, it tries to resubscribe since the earliest stored event in the event bus. See the `onError()` method in `Subscribe.java`.
57
65
58
66
# Limitations
59
67
1. No guarantees that streams will remain open with `PublishStream` examples - Pub/Sub API has idle timeouts and will close idle streams. If a stream is closed while running these examples, you will most likely need to stop and restart.
60
68
2. No support for republishing on error - If an error occurs while publishing the relevant examples will surface the error but will not attempt to republish the event.
61
69
3. No security guarantees - Teams using these examples for reference will need to do their own security audits to ensure the dependencies introduced here can be safely used.
62
-
4. No performance testing - These examples have not been perf tested.
70
+
4. No performance testing - These examples have not been perf tested.
Copy file name to clipboardExpand all lines: java/src/main/java/accountupdateapp/README.md
+8-2
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ This example subscribes to change events corresponding to the creation of [Accou
9
9
* Search for the `Account` object and click on the right arrow in the middle of the screen to select the entity.
10
10
* Click on the `Save` button to update the changes.
11
11
2. The `NewAccount` custom platform needs to be created with the following fields:
12
-
-Standard Fields
12
+
-Platform Event Name
13
13
- Label: `NewAccount`
14
14
- Plural Label: `NewAccounts`
15
15
- Custom Fields
@@ -35,5 +35,11 @@ This example subscribes to change events corresponding to the creation of [Accou
35
35
```
36
36
37
37
## Notes:
38
-
* Subscribers in both the `AccountUpdater` and `AccountListener` subscribe with the ReplayPreset set to LATEST. Therefore, only events generated once the examples have started running will be processed
38
+
* Please use the `my domain` URL for your org for running these examples. You can find the my domain URL through Developer Console.
39
+
* Open Developer Console
40
+
* Click on the Debug menu and select Open Execute Anonymous Window.
41
+
* Key in the following in the window: `System.debug(System.url.getOrgDomainUrl());` and execute the same.
42
+
* Once done, in the Logs tab below open the logs recently executed code.
43
+
* In the logs, get the `my domain` URL from the USER_DEBUG event.
44
+
* Subscribers in both the `AccountUpdater` and `AccountListener` subscribe with the ReplayPreset set to LATEST. Therefore, only events generated once the examples have started running will be processed.
39
45
* The `AccountUpdater` logs the `AccountNumber` that has been added to the `Account` record which can be used to verify if the update is correct.
0 commit comments