Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RecoverableUpdateStream

An extension to UpdateStream that includes recovery functionality.

A recoverable update stream wraps an UpdateStream, tracking topic updates and associated Promisess.

In the event that a RecoverableUpdateStream returns a Promise that rejects, calling RecoverableUpdateStream.isRecoverable returns true recovery is possible.

Call RecoverableUpdateStream.recover to re-establish the update stream and re-play incomplete topic updates before resuming.

Construct a RecoverableUpdateStream by passing a RetryStrategy to UpdateStreamBuilder.build

Example feature use

This example demonstrates use of a RecoverableUpdateStream to update topic my/topic with 1000 unique values, after which it checks for failure in any of them. If any topic updates complete exceptionally and the exception is recoverable, the code recovers - reestablishing an UpdateStream and delivering the failed topic updates.

const topicSpec = new TopicSpecification(TopicType.STRING);

const updateStream =
    session.topics
        .newUpdateStreamBuilder()
        .specification(topicSpec)
        .build(
            'my/topic',
            datatypes.string(),
            { interval: 1000, attempts: 10 }
        );

const promises = [ ...Array(1000).keys() ]
    .map((i) => updateStream.set(`Value of ${i}`));

try {
    await Promise.all(promises);
} catch (err) {
    if (updateStream.isRecoverable()) {
        updateStream.recover();
    } else {
        console.error("Cannot recover", err);
    }
}
since

6.10

Hierarchy

Index

Methods

get

  • get(): any
  • Return the latest value of the topic set using this update stream.

    The returned value reflects the last value that has been set, before it is sent to the server.

    If the server rejects a set operation, the topic value will not change and this update stream will be invalidated.

    This method will throw an Error if called before the first call to set

    Returns any

    the cached value of the topic

isRecoverable

  • isRecoverable(): boolean

recover

  • Reestablish the inner recovery stream. Deliver pending topic updates.

    If recoverable exceptions occur during recovery then pause and retry, where the pause duration and the maximum number of retries is governed by the RetryStrategy supplied to builder function UpdateStreamBuilder.build.

    If non-recoverable errors occur during recovery then recovery is aborted.

    If recovery fails for any reason then further recovery attempts will fail.

    throws

    an Error if recovery is not possible with the limits of the retry strategy.

    Returns Result<void>

set

  • Sets the topic to a specified value.

    null or undefined can only be passed to the value parameter when updating string, int64 or double topics.

    When a topic of type string, int64 or double is set to null or undefined , the topic will be updated to have no value. If a previous value was present subscribers will receive a notification that the new value is undefined . New subscribers will not receive a value notification.

    If this method fails once, all subsequent calls to {@link #set} or {@link #validate} will also fail.

    Parameters

    • value: any

      the value. Update streams for string, int64, and double topics accept null or undefined, as described above. Using null with other topic types is an error and will result in an Error .

    Returns Result<TopicCreationResult | void>

    a Result that completes when a response is received from the server.

    The first set operation will return a TopicCreationResult indicating whether a new topic was created or it already exists.

    If the task fails, the Result will resolve with an Error .

validate

  • Validates the update stream.

    Update streams are validated lazily when setting the value. This method allows the stream to be validated before a value needs to be set.

    If the update stream has not been validated yet, calling this method checks the topic exists, the topic type is correct, the constraint is satisfied and the session has permission to update the topic. Once it has been validated calling this method checks the topic has not been removed, no other stream has been created for the topic, the value of the topic has not been changed by anything else and the session still has permission to update the topic. If validation fails, the Result will resolve with an Error.

    If this method fails all subsequent calls to set or validate will resolve with an Error.

    Returns Result<TopicCreationResult>

    a Result that completes when a response is received from the server.