\r\n

51Degrees Pipeline Node.js  4.2Newer Version 4.3

51Degrees Pipeline for Node.js

usageSharing/usageSharing.js

This Example shows how to configure the usage sharing feature of the Pipeline API. Usage sharing is a feature that allows you to share details of the requests you are processing with 51Degrees.

Usage sharing works by adding a 'ShareUsageElement' to the pipeline. This element will collect evidence values as they pass through, periodically sending them to 51Degrees for processing.

If you want to know more about usage sharing, and why you should consider using it, see the usage sharing feature page.

Usage sharing is enabled by default if using some 51Degrees pipeline builders such as the DeviceDetectionOnPremisePipelineBuilder In this example, we show how to specifically add a shareUsage element to a Pipeline using configuration.

As with all flow elements, this can also be handled in code, using the constructor parameters. The commented section in the example demonstrates this.

The 51d.json file contains all the configuration options. These are all optional, so each can be omitted if the default for that option is sufficient:

{
"PipelineOptions": {
"Elements": [
{
"elementName": "../../shareUsage",
"elementParameters": {
"sharePercentage": 100,
"interval": 1200000,
"requestedPackageSize": 50,
"cooke": "",
"queryWhitelist": [],
"headerBlacklist": []
}
}
]
}
}

For details of what each setting does, see the constructor parameters in the reference documentation for the share usage element

This example is available in full on GitHub.

Expected output

Constructing pipeline from configuration file.
Pipeline created with share usage element. Evidence processed
with this pipeline will now be shared with 51Degrees using the
specified configuration.
/* *********************************************************************
* This Original Work is copyright of 51 Degrees Mobile Experts Limited.
* Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
* Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
*
* This Original Work is licensed under the European Union Public Licence (EUPL)
* v.1.2 and is subject to its terms as set out below.
*
* If a copy of the EUPL was not distributed with this file, You can obtain
* one at https://opensource.org/licenses/EUPL-1.2.
*
* The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
* amended by the European Commission) shall be deemed incompatible for
* the purposes of the Work and the provisions of the compatibility
* clause in Article 5 of the EUPL shall not apply.
*
* If using the Work as, or as part of, a network application, by
* including the attribution notice(s) required under Article 5 of the EUPL
* in the end user terms of the application under an appropriate heading,
* such notice(s) shall fulfill the requirements of that article.
* ********************************************************************* */
const core = require('fiftyone.pipeline.core');
// Note that this example is designed to be run from within the
// source repository. If this code has been copied to run standalone
// then you'll need to replace the require below with the commented
// out version below it.
const engine51 = require('../..');
// const engine51 = require("fiftyone.pipeline.engines.fiftyone");
console.log('Constructing pipeline from configuration file.');
console.log();
// Create a new pipeline from the supplied config file.
const pipeline = new core.PipelineBuilder().buildFromConfigurationFile('51d.json');
// Alternatively, the commented code below shows how to
// configure the ShareUsageElement in code, rather than
// using a configuration file.
//const usageElement = new engine51.ShareUsage({
// sharePercentage: 0.1,
// requestedPackageSize: 2000,
//});
//const pipeline = new core.PipelineBuilder().add(usageElement).build();
console.log(`Pipeline created with share usage element. Evidence processed
with this pipeline will now be periodically shared with 51Degrees using the
specified configuration.`);