Service Discovery

Fog Apps or Services typically depend on other services which are running in different containers. Service discovery helps applications or services locate dependent services.

All micro services communicate with only Message Broker, so typically they need to discover the messaging broker (IP address and port). Similarly, all applications communicate with only the North Bound Interface (NBI) Gateway, so they need to discover where the NBI is running (NBI service's IP address and port).


Service Mappings to Network Location

When a service bundle is installed, IOx hosting infrastructure needs to know all the services that are part of the bundle. IOx hosting infrastructure also needs to know the interface and port on which a service is listening, if the service is opening a network port for running a server.

In order to do so, the services must add "port-mapping" key while defining the "provides" section.

Port-mapping follows a pattern interfaceName:transport_type:port.

For example, the core service bundle provides NBI service listening at tcp port 8080 and and also broker service listening at tcp port 4222. See following the package.yaml.

service-bundle:
 provides:
   -
     id: "urn:cisco:system:service:nbi"
     version: 1.5
     api-version: 1     
     port-mapping: ["eth0:tcp:8080"]
     description: provides NBI gateway service
   -
     id: "urn:cisco:system:service:message-broker"
     version: 1.5
     api-version: 2     
     port-mapping: ["eth0:tcp:4222"]
     description: provides Message bus service
   -
     id: "urn:cisco:system:service:provisioning"
     version: 1.0
     api-version: 1
 
 app:
   network:    
     interface-name: eth0
     ports:       
       tcp: [4222, 8080]       

Application Depends on a Service

When an application requests access to a service, CAF will get the coordinates (IP, PORT) of the service requested and inject them as ENV variables in to the application namespace.

In order to form the environment variables name, the dependent entity should provide list of services which it is dependent upon. Any application that depends on the IOx service will communicate via NBI. By default, the label exposed is "nbi" for Apps.

Example: An application is trying to consume via GPS service with deploy id as IOxGPS.

  
  #specify dependent services
  depends-on:
    packages:
      -
        name: "IOxGPS"
        version: "1.5.0"

        

The following ENV variables get injected into the app/service runtime environment:

export nbi_IP_ADDRESS = <Reachable IP Address>
export nbi_TCP_8080_PORT = <Reachable port number>

These environment variables can be used to find out the IP address and port which were assigned to the NBI service on which app depends upon.

Service Depends on a Service

Any service to service communication happens via Message Broker provided as part of IOxCore services. When an Service depends on another IOx service, CAF will inject the broker IP and PORT details as ENV variables into the service container.

Example: A service depends on IOxCore.

  #specify dependent service
  depends-on:
    packages:
      -
        name: "IOxCore"
        version: "1.7.0"

By default, the label exposed is "message_broker" for Apps.

The following ENV variables get injected into the service run time environment:

export message_broker_IP_ADDRESS = <Reachable IP Address>
export message_broker_TCP_4222_PORT = <Reachable port number>

Next steps