AboutSupportDeveloper GuideVersion 40.130.101.1

A messaging bus that allows for pub/sub messaging between different applications.

Hierarchy

  • Base
    • InterApplicationBus

Properties

Channel: OpenFin.Channel
events: {
    subscriberAdded: string;
    subscriberRemoved: string;
} = ...
on: any
removeAllListeners: any

Accessors

  • get me(): Identity
  • Returns Identity

    me should only be accessed from the fin global (FinApi.me); access through entity classes is not guaranteed to behave sensibly in all calling contexts.

Methods

  • Publishes a message to all applications running on OpenFin Runtime that are subscribed to the specified topic.

    Parameters

    • topic: string

      The topic on which the message is sent

    • message: any

      The message to be published. Can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    fin.InterApplicationBus.publish('topic', 'hello').then(() => console.log('Published')).catch(err => console.log(err));
    
  • Sends a message to a specific application on a specific topic.

    Parameters

    • destination: {
          name?: string;
          uuid: string;
      }

      The identity of the application to which the message is sent

      • Optionalname?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • message: any

      The message to be sent. Can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    fin.InterApplicationBus.send(fin.me, 'topic', 'Hello there!').then(() => console.log('Message sent')).catch(err => console.log(err));
    
  • Subscribes to messages from the specified application on the specified topic.

    Parameters

    • source: {
          name?: string;
          uuid: string;
      }

      This object is described in the Identity in the typedef

      • Optionalname?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • listener: any

      A function that is called when a message has been received. It is passed the message, uuid and name of the sending application. The message can be either a primitive data type (string, number, or boolean) or composite data type (object, array) that is composed of other primitive or composite data types

    Returns Promise<void>

    // subscribe to a specified application
    fin.InterApplicationBus.subscribe(fin.me, 'topic', sub_msg => console.log(sub_msg)).then(() => console.log('Subscribed to the specified application')).catch(err => console.log(err));

    // subscribe to wildcard
    fin.InterApplicationBus.subscribe({ uuid: '*' }, 'topic', sub_msg => console.log(sub_msg)).then(() => console.log('Subscribed to *')).catch(err => console.log(err));
  • Unsubscribes to messages from the specified application on the specified topic.

    Parameters

    • source: {
          name?: string;
          uuid: string;
      }

      This object is described in the Identity in the typedef

      • Optionalname?: string
      • uuid: string
    • topic: string

      The topic on which the message is sent

    • listener: any

      A callback previously registered with subscribe()

    Returns Promise<void>

    If you are listening to all apps on a topic, (i.e you passed { uuid:'*' } to the subscribe function) then you need to pass { uuid:'*' } to unsubscribe as well. If you are listening to a specific application, (i.e you passed { uuid:'some_app' } to the subscribe function) then you need to provide the same identifier to unsubscribe, unsubscribing to * on that same topic will not unhook your initial listener otherwise.

    const listener = console.log;

    // If any application publishes a message on topic `foo`, our listener will be called.
    await fin.InterApplicationBus.subscribe({ uuid:'*' }, 'foo', listener)

    // When you want to unsubscribe, you need to specify the uuid of the app you'd like to
    // unsubscribe from (or `*`) and provide the same function you gave the subscribe function
    await fin.InterApplicationBus.unsubscribe({ uuid:'*' }, 'foo', listener)