Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4785

Allow a custom transport layer to be provided as MongoClient option

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Connection Layer
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Example

      Provide a socket creator method to the MongoClient

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const client = new MongoClient('xx', { 
        createSocket(options) {
          return new MinimalSocketInterfaceImplemention();
        }
      })
      

      Details

      Add support for providing a function or object with a small number of needed methods to construct a transport layer that is customized by the user. When specified all "sockets" will be created using this method and connected to the driver's MessageStream I/O handler.

      The following is the minimal "socket" interface required by the driver

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      type MinimalSocketInterface = {
        // Optional, but sync IO to make a UUID occurs if these don't exist.
        remoteAddress: string;
        remotePort: number;
        // TCP specific
        setKeepAlive: (enable: boolean, initialDelayMS: number) => void;
        setTimeout: (timeoutMS: number) => void;
        setNoDelay: (noDelay: boolean) => void;
        // MessageStream requirement
        pipe: <T extends NodeJS.WritableStream = any>(stream: T) => void;
        // These are all used only during setup (connecting)
        on: (eventName: string, listener: (event: any) => void) => void;
        once: (eventName: string, listener: (event: any) => void) => void;
        emit: (eventName: string) => void;
        removeAllListeners: (eventName: string) => void;
        removeListener: (eventName: string) => void;
        // MessageStream internally calls write as Msgs are pushed to it
        write: (chunk: any) => void;
        // Two different shutdown APIs
        end: (callback: () => void) => void;
        destroy: () => void;
      };
      

      I think it would help to also reduce some of the surface area here, such as, only using removeAllListeners and only call the TCP specific methods when the connection is known to be TCP from Node.js APIs.

      AC

      • TBD
      POC

      https://github.com/mongodb/node-mongodb-native/blob/what-if-ws/test/integration/node-specific/web_sockets.test.ts#L160

            Assignee:
            Unassigned Unassigned
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: