Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
lightstreamer-adapter
Advanced tools
This package includes the resources needed to write Data Adapters and Metadata Adapters for Lightstreamer Server in a Node.js environment. The adapters will run in a separate process, communicating with the Server through the Adapter Remoting Infrastructu
This package includes the resources needed to write Data Adapters and Metadata Adapters for Lightstreamer Server in a Node.js environment. The adapters will run in a separate process, communicating with the Server through the Adapter Remoting Infrastructure.
Install the package using npm
npm install lightstreamer-adapter
Download and install Lightstreamer
Go to the "adapters" folder of your Lightstreamer Server installation. Create a new folder to deploy the remote adapters in, let's call it "NodeAdapter".
Create an "adapters.xml" file inside the "NodeAdapter" folder and use the following contents (this is an example configuration, you can modify it to your liking by using the generic template for basic and robust Proxy Adapters as a reference):
<?xml version="1.0"?>
<adapters_conf id="PROXY_NODE">
<metadata_adapter_initialised_first>N</metadata_adapter_initialised_first>
<metadata_provider>
<adapter_class>ROBUST_PROXY_FOR_REMOTE_ADAPTER</adapter_class>
<classloader>log-enabled</classloader>
<param name="request_reply_port">8003</param>
<param name="timeout">36000000</param>
</metadata_provider>
<data_provider>
<adapter_class>ROBUST_PROXY_FOR_REMOTE_ADAPTER</adapter_class>
<classloader>log-enabled</classloader>
<param name="request_reply_port">8001</param>
<param name="timeout">36000000</param>
</data_provider>
</adapters_conf>
Take note of the ports configured in the adapters.xml file as those are needed to write the remote part of the adapters.
Create a .js file, let's call it "adapters.js"
Get the net package and create the connections to Lightstreamer server. Note that the ports are the same used in the above file; LIGHTSTREAMER_SERVER_HOST is the host of the Lightstreamer server e.g.: "localhost".
var net = require('net'),
dataStream = net.createConnection(8001, LIGHTSTREAMER_SERVER_HOST),
metadataStream = net.createConnection(8003, LIGHTSTREAMER_SERVER_HOST);
Get the adapter classes and create the needed instances
var MetadataProvider = require('lightstreamer-adapter').MetadataProvider,
var DataProvider = require('lightstreamer-adapter').DataProvider,
dataProvider = new DataProvider(dataStream),
metadataProvider = new MetadataProvider(metadataStream);
Now you can register the events to respond to the adapters duties; see the documentation for the details
dataProvider.on('subscribe', function(itemName, response) {
//HERE start sending updates for the itemName item
response.success();
});
dataProvider.on('unsubscribe', function(itemName, response) {
//HERE stop sending updates for the itemName item
response.success();
});
metadataProvider.on('notifyUserMessage', function(request, response) {
//HERE handle user message
response.success();
});
Send updates for an item. Note that sending updates for items no one has subscribed to will result in an error, hence this calls must be bound to the "start/stop sending updates" comments int he subscribe/unsubscribe events:
dataProvider.update(itemName, false, {
'field1': valField1,
'field2': valField2
});
From the command line call
node adapters.js
var lsClient = new LightstreamerClient(LIGHTSTREAMER_SERVER_HOST,"PROXY_NODE");
lsClient.connect();
Note that the "PROXY_NODE" string is taken from the adapters.xml
http://www.lightstreamer.com/api/ls-nodejs-adapter/1.7.0/
This section is dedicated to developers who want to extend/modify the library itself, if you're simply looking to use it, ignore it.
We want to write code to use our package by requiring "lightstreamer-adapter" without having to specify the full path. On the other hand, during development, we do not want to install the package from the repo as we want to, in fact, test it before putting it on the repo for everyone else to enjoy. So:
npm link
npm link lightstreamer-adapter
NOTE: You can't globally link the package (using -g) to make it available everywhere
First install nodeunit
npm -g install nodeunit
The -g unit will install it on the system instead of installing it locally; you may remove it if you prefer a local installation
Go to the test folder and run the following commands
nodeunit dataprotocol.test.js
nodeunit dataprovider.test.js
nodeunit metadataprotocol.test.js
nodeunit metadataprovider.test.js
jsdoc --recurse --destination docs lib
The API documentation will be available in the docs folder.
Compatible with Adapter Remoting Infrastructure since Server version 7.4.
[1.7.0] (15 Jul 2023)
Introduced the support for a single stream instead of two for the communication of the Remote Data Adapters. In fact, since Server version 7.4, the Proxy Data Adapter can (and should) be configured to use a single connection for the communication. Hence, the second argument of the DataProvider constructor (notifyStream) has been removed, as well as the getNotifyStream method. Moreover, for clarity, the first argument of the DataProvider constructor (reqRespStream) has been renamed as "stream" and, for consistency, the getReqRespStream method has been renamed as "getStream".
Changed most of the supplied tests in dataprovider.test.js to operate in the new single-stream case. Tests for the double-stream case have been left only where most significant.
Clarified the meaning of a null value for a "clientMessage" property supplied in the "exceptionData" parameter on a "error" invocation when "exceptionType" is "credits": an empty string should be sent to the client. Note that, before 7.4, the Server used to send the "null" string as a placeholder.
Fixed a bug in the interface, as getReqRespStream and getNotifyStream of DataProvider, and getStream of MetadataProvider were erroneously named reqRespStream, notifyStream, and stream, respectively. Note that these getters are provided only for the sake of completeness and, for this reason, they are not expected to be leveraged. Also note that, because of the extensions in the DataProvider class described above, only a getStream method is now provided for this class.
Compatible with Adapter Remoting Infrastructure since Server version 7.4
If an existing Remote Server based on this SDK launches a Remote Data Adapter, it cannot be upgraded to this new SDK version seamlessly. The upgrade will require a change in the code to open a single connection to the Proxy Data Adapter and use the new reduced DataAdapter constructor. This, in turn, will require the configuration of a single port on the Proxy Data Adapter, which is only possible with Lightstreamer Server 7.4 or later. However, if a Remote Server only launches Remote Metadata Adapters, the compatibility with Server version 7.3 is kept.
If a Remote Metadata Adapter supplies a null value for "clientMessage" and relies on the Server sending the "null" string to the clients, now it should supply "null" explicitly.
FAQs
This package includes the resources needed to write Data Adapters and Metadata Adapters for Lightstreamer Server in a Node.js environment. The adapters will run in a separate process, communicating with the Server through the Adapter Remoting Infrastructu
The npm package lightstreamer-adapter receives a total of 26 weekly downloads. As such, lightstreamer-adapter popularity was classified as not popular.
We found that lightstreamer-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.