Interface IPubSubSystem<AD, I, O>

The default Publish and Subscribe System.

The System contains of publishers and subscribers which are linked using topics (based on strings).

  • To add new publishers or subscribers use the function: register and provide the required options (see register)
  • To add new subscriber you can use the function : registerSubscription which will receive a topic and a callback (see registerSubscription)
  • After adding publishers or subscribers you can change the behavior using updateOptions (see updateOptions)
  • To remove publishers or subscribers use unregister (see unregister)
  • to emit data use emit (see emit)
  • internally, if a subscriber / publisher is added, its options are changed or its removed, the pub sub system updates an matching structure. In the case you want to perform this manually execute updateMatching
  • to check which publishers and subscribers are present, checkout the corresponding properties.
  • You can subscribe to incremental changes using the eventEmitter onIncrementalDataChange
  • If the pub-sub-system isnt needed any more dispose it!

The publisher might be observabes or eventEmitters.

The IPubSubSystem is implemented by the PubSubSystemBase-Class

The Behavior may differ based on the settings. Your are not able to change these options, after the instance has been created. (see IPubSubOptions for details) The Default of these options are settings are.

{
mqttPatternBasedSubscriptions: true,
forwardChildData: true,
forwardParentData: true,
matchTopicsWithoutWildcards: true,
}

Example 1

// Describe the required Test:
let pubSubSystem = new PubSubSystemBase({
generateEmitterType: function () {
return new NopeEventEmitter() as INopeEventEmitter;
},
});


// Create a Publisher for the system:
let publisher: INopeEventEmitter = new NopeEventEmitter();

pubSubSystem.register(publisher, {
mode: "publish",
schema: {},
topic: "this/is/a/test",
});

// Create a Subscriber
let subscriber: INopeEventEmitter = new NopeEventEmitter();

subscriber = pubSubSystem.register(subscriber, {
mode: "subscribe",
schema: {},
topic: "this/#",
});

subscriber.subscribe(console.log);
publisher.emit("Hello World!"); // Logs the following => "Hello World!", {...}

Author

M.Karkowski

Export

Type Parameters

Hierarchy

Implemented by

Properties

emitters: {
    publishers: {
        name: string;
        schema: INopeDescriptor;
    }[];
    subscribers: {
        name: string;
        schema: INopeDescriptor;
    }[];
}

List all known Emitters in the System.

Type declaration

An observable which holds the incremental data change. this will be triggered, if the an emitter (publisher) changes its data. Contains only the last emitted data and the topic

// Describe the required Test:
let pubSubSystem = new PubSubSystemBase({
generateEmitterType: function () {
return new NopeEventEmitter() as INopeEventEmitter;
},
});


// Create a Publisher for the system:
let publisher: INopeEventEmitter = new NopeEventEmitter();

pubSubSystem.register(publisher, {
mode: "publish",
schema: {},
topic: "this/is/a/test",
});


pubSubSystem.onIncrementalDataChange.subscribe(console.log);
publisher.emit("Hello World!"); // Logs the following => {path: "this/is/a/test", data: "Hello World!"}

Author

M.Karkowski

Memberof

IPubSubSystem

Options which describe the Behavior

Author

M.Karkowski

Memberof

IPubSubSystem

publishers: IMapBasedMergeData<O, IPubSubEmitterOptions<AD>, O, string>

List containing all publishers.

Author

M.Karkowski

Memberof

IPubSubSystem

subscriptions: IMapBasedMergeData<O, IPubSubEmitterOptions<AD>, O, string>

List, containing all subscribers.

Author

M.Karkowski

Memberof

IPubSubSystem

Methods

  • Emits an Events and all subscribes, where the pattern matches will be informed

    Author

    M.Karkowski

    Memberof

    IPubSubSystem

    Parameters

    • path: string

      The Topic.

    • data: any

      The Data of the Event.

    • Optional options: Partial<AD>

    Returns void

  • Function to register an Observable. Please define the Options, to decide whether the data of the observable should be published or subscribed.

    Author

    M.Karkowski

    Returns

    {O}

    Memberof

    IPubSubSystem

    Parameters

    Returns O

  • Lists all publishers and subscribers of the system.

    Returns {
        publishers: {
            name: string;
            schema: INopeDescriptor;
        }[];
        subscribers: {
            name: string;
            schema: INopeDescriptor;
        }[];
    }

  • Removes an observable of the Pub-Sub-System.

    Author

    M.Karkowski

    Returns

    {boolean}

    Memberof

    IPubSubSystem

    Parameters

    • emitter: I

    Returns boolean

  • Helper to manually Trigger an update of the Matching. This will update subscribers and publishers and link them. Normally this is not necessary.

    This will build an internal linking (based on the settings) between publishers and subscribers.

    Author

    M.Karkowski

    Memberof

    IPubSubSystem

    Returns void

  • Function to update the options and there by the topics of an observable.

    Author

    M.Karkowski

    Memberof

    IPubSubSystem

    Parameters

    • emitter: I

      The Emitter to consider

    • options: IEventOptions

      The modified options

    Returns void

Generated using TypeDoc