Step 3: Publish Events and Verify the Managed Subscription
Publish events by using the PublishStream
RPC. Then verify that the subscription resumes after the last received event after restarting it and calling ManagedSubscribe
RPC with the same managed subscription ID.
The ManagedSubscribe
RPC method is part of a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.
- In
arguments.yaml
, supply these arguments.SINGLE_PUBLISH_REQUEST: true
: This argument specifies that all events are sent in one publish request.TOPIC: /event/Order_Event__e
: This argument specifies the topic for event publishing.
- Modify the publishing code to specify the event fields and values to publish. In
java/src/main/java/utility/CommonContext.java
, modify thepublic List<GenericRecord> createEventMessages(Schema schema, final int numEvents)
method. Replace the<User_Id>
placeholder value of theCreatedById
field with a valid user ID in your Salesforce org. To get the user ID, see Find the Salesforce ID for a User or Profile.
-
In a second terminal window, go to the top-level
java
folder in yourpub-sub-api
folder. -
To build the Java client, enter
mvn clean install
. -
To run the
PublishStream
RPC example, enter./run.sh genericpubsub.PublishStream
.The example publishes five events as set in the
arguments.yaml
default configuration. It prints out logging information to the terminal. -
Return to the terminal for the
ManagedSubscribe
client, and verify that the logging output shows the five events received. Also, the log output shows that a commit request is sent after the batch of events is received to commit the Replay ID. The output looks similar to this output.
-
To disconnect the
ManagedSubscribe
client, press Ctrl+C in the terminal. -
Publish more events while the subscriber is disconnected.
a. To differentiate the events that are published next from the previous events, modify the Order Number field values so that they’re higher than the previous numbers. In
java/src/main/java/utility/CommonContext.java
, in thecreateEventMessages(Schema schema, final int numEvents)
method, replace theorderNumbers
array with this statement.b. Because you modified the publishing code, rebuild the Pub/Sub API Java client. From the top-level java folder, enter
mvn clean install
.c. In the
PublishStream
client terminal, run the client by entering./run.sh genericpubsub.PublishStream
.d. Verify that all five new events are published.
-
Return to the
ManagedSubscribe
client terminal. Restart the managed subscription by entering./run.sh genericpubsub.ManagedSubscribe
. -
The subscription resumes after the last received event, starting with the missed events. The
ManagedSubscribe
client output shows all the remaining events received with order numbers104
through108
. Also, the log output shows that a commit request is sent after the batch of events is received to commit the Replay ID.
Thanks to managed subscriptions (beta), you can track the events processed in your subscriptions. You don’t worry about how to catch up on missed events after a subscriber client is disconnected.