Generic Services

Apcera provides the Generic Service Gateway for integrating with external systems. This section describes how to implement services using the generic service type, including:

Using generic services

The generic service gateway takes a URL as a service creation parameter and returns the same URL for any application that binds to it. This can be useful for any service that requires simple point-to-point connectivity and including any credentials or parameters that may be necessary to provide to the application.

Typically, you use the generic service gateway to connect jobs to an existing external system, such as a existing MySQL database. In this case you are using the generic service type to simply allow egress to the backend system.

Creating generic services

The following command creates a generic service gateway whose URL points to a MongoDB instance:

apc service create userdb --type generic -- --url "mongodb://admin:password@foobar.example.com:35533/users"

In the command the --type option specifies the generic service type, and --url specifies the service URL to expose to jobs. The -- that precedes --url indicates that all subsequent command parameters apply to the specific service provider, and not to the apc service create command.

An existing job can bind to the above service as follows:

apc service bind userdb --job nodeApp

In this case the URL specified by --url is made available to the job via an environment variable named USERDB_URI.

For example, a Node application bound to the userdb service could connect to the associated MongoDB instance with the following code:

var mongodb = require('mongodb');
var MongoClient = mongodb.MongoClient;

// Read connection string from environment 
var url = process.env.USERDB_URI;

MongoClient.connect(url, function(err, db) {
    if (err) {
        console.log('Unable to connect to the mongoDB server. Error:', err);
    } else {
        console.log('Connection established to', url);
        db.close();
    }
});

Additional generic service examples

See Connecting to an existing MySQL database for a step-by-step guide to connecting to a pre-existing MySQL database set up outside of the Apcera Platform.

See Creating a LDAP service using a generic service gateway for a step-by-step implementation using the generic service gateway to create LDAP and LDAPS services.