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.

  1. 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.
  2. Modify the publishing code to specify the event fields and values to publish. In java/src/main/java/utility/CommonContext.java, modify the public List<GenericRecord> createEventMessages(Schema schema, final int numEvents) method. Replace the <User_Id> placeholder value of the CreatedById 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.
  1. In a second terminal window, go to the top-level java folder in your pub-sub-api folder.

  2. To build the Java client, enter mvn clean install.

  3. 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.

  4. 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.

  1. To disconnect the ManagedSubscribe client, press Ctrl+C in the terminal.

  2. 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 the createEventMessages(Schema schema, final int numEvents) method, replace the orderNumbers 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.

  3. Return to the ManagedSubscribe client terminal. Restart the managed subscription by entering ./run.sh genericpubsub.ManagedSubscribe.

  4. 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 numbers 104 through 108. 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.