Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how apps should handle broadcast and receipt of multiple context types #434

Closed
Tracked by #452
kriswest opened this issue Jul 27, 2021 · 1 comment · Fixed by #464
Closed
Tracked by #452

Clarify how apps should handle broadcast and receipt of multiple context types #434

kriswest opened this issue Jul 27, 2021 · 1 comment · Fixed by #464
Assignees
Labels
api FDC3 API Working Group channels feeds & transactions Channels, Feeds & Transactions Discussion Group context-data FDC3 Context Data Working Group docs Documentation
Milestone

Comments

@kriswest
Copy link
Contributor

Enhancement Request

When sharing context over channels, you can addContextListner for all context or for particular types of context (which will filter the messages you receive). However, the specification does not advise on whether an application, intended to link to multiple other applications consuming a variety of different types, should broadcast multiple times with different types or expect the other applications to listen for its preferred type and extract what they need for it.

Use Case:

A particular application (e.g. an OMS) might broadcast details of orders (lets call that fdc3.order for the sake of the example). A type representing an order might be composed of several other types, including:

  • A Position (fdc3.position)
  • An Instrument (fdc3.instrument)
  • An Organisation (fdc3.organization)
  • A Contact (fdc3.contact)

That application might be linked (via a System channel) to other components that use particular types as context, e.g.

  • a CRM (fdc3.contact),
  • an account management tool (fdc3.organization)
  • a pricing chart (fdc3.instrument)
  • a news feed (fdc3.instrument)
  • a risk tool (fdc3.position)
  • a notification or order update tool (fdc3.order)
  • etc.

Possible solutions

Should the OMS:

  • Broadcast just the fdc3.order type?
    • This encodes all the required information for all the other components
    • However the other components would have to be expecting it and/or ready to extract the types they need from it
  • Broadcast all 5 types separately one after another
    • Each component can listen for only the type they require
    • Generates additional load on the system by multiplying each broadcast
    • Potentially need to rebroadcast every type or need to know which other types are expected to be re-broadcast.

This question may need to be answered for components that use different types to be able to work together without prior coordination. That answer could form advice in the specification OR could update it (e.g. to have context listeners added to channels automatically extract types they are listening for).

Note: it is possible to write a general purpose function for searching for and extracting a specified type from another type that is composed from it:

/** Recursively search the input context and return an array of matches */
let extractContextTypeHelper = (contextReceived, typeDesired, list) => {
    if (contextReceived?.type == typeDesired) {
        //if we found the type we want return it
        return [contextReceived];
    } else if (contextReceived instanceof Array){
        //if we received an array we need to check each item, return a match, or return a list of each entries children to check
        for (let i=0; i < contextReceived.length; i++){
            if (contextReceived[i]?.type == typeDesired) {
                //if we found the type we want return it
                return contextReceived[i];
            }
            let found = extractContextTypeHelper(contextReceived[i], typeDesired, [])
            if (found) {
                list = list.concat(found);
            } 
        }
        return extractContextTypeHelper(list, typeDesired, []);
    } else if (typeof contextReceived == "object"){
        //if we received an object thats not the right type, extract its fields and add to our list
        let keys = Object.keys(contextReceived);
        for (let i=0; i < keys.length; i++) {
            let found = extractContextTypeHelper(contextReceived[keys[i]], typeDesired, []);
            if (found) {
                list = list.concat(found);
            } 
        }

        return list;
    }

    return list;
}

/** Return the first match found or null if none is found */
let extractContextType = (contextReceived, typeDesired) => {
    let found = extractContextTypeHelper(contextReceived, typeDesired, []);
    if (found && found.length > 0) {
        return found[0];
    }
    return null;
};

/** Example of usage */

let example = {
  type: "fdc3.order",
  instrument: {
    type: "fdc3.instrument",
    name: "AAPL",
    id: {
      ticker: "AAPL"
    }
  },
  amount: 100,
  direction: "buy",
  client: {
    type: "fdc3.client",
    organization: {
      type: "fdc3.organization",
      name: 'Cargill, Incorporated',
      id: {
        LEI: 'QXZYQNMR4JZ5RIRN4T31',
        FDS_ID: '00161G-E'
      }
    },
    contact: {
      type: 'fdc3.contact',
      name: 'Jane Doe',
      id: {
        email: 'jane.doe@mail.com'
      }
    }
  }
};

extractContextType(example, "fdc3.instrument")
extractContextType(example, "fdc3.contact")  
extractContextType(example, "fdc3.organization")
extractContextType(example, "fdc3.order")
@kriswest kriswest added enhancement New feature or request docs Documentation api FDC3 API Working Group context-data FDC3 Context Data Working Group channels feeds & transactions Channels, Feeds & Transactions Discussion Group labels Jul 27, 2021
@kriswest kriswest added this to the 2.0-candidates milestone Sep 7, 2021
@kriswest
Copy link
Contributor Author

kriswest commented Sep 9, 2021

Output from #452

  • Consensus achieved that apps should broadcast all the types that they expect other apps to respond to (allows use of typed context listeners for filtering, lower complexity and easier to understand)
  • Raise PR to Improve recommendations for broadcast context single vs. multiple types (for composite types) in the docs and specification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api FDC3 API Working Group channels feeds & transactions Channels, Feeds & Transactions Discussion Group context-data FDC3 Context Data Working Group docs Documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant