1.2.2 • Published 1 year ago

@nick-iotex/w3bstream-http-client-simulator v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Simulator README

This README provides an overview of the Simulator module, which is designed to generate and send simulated data points to the W3BSTREAM server.

Table of Contents

Getting Started

To use the Simulator module, you need to import it along with some dependencies:

import {
  Simulator,
  DataPointGenerator,
} from "@nick-iotex/w3bstream-http-client-simulator";

Usage

Create message generator

Deside what the shape of the data point should be:

type TemperatureDataPoint = {
  temperature: number;
  timestamp: number;
};

And how the data point should be generated, you can use randomizer or timestampGenerator methods of DataPointGenerator:

const generatorFunction = () => ({
  temperature: DataPointGenerator.randomizer(0, 100),
  timestamp: DataPointGenerator.timestampGenerator(),
});

And finally, to generate messages, instantiate data generator:

const dataGenerator = new DataPointGenerator<TemperatureDataPoint>(
  generatorFunction
);

Simulator initialization

Create a new instance of the Simulator class, initialize it and set a DataPointGenerator that you created earlier:

const simulator = new Simulator(pubId, pubToken, w3bstreamEndpoint);
simulator.init();
simulator.dataPointGenerator = dataGenerator;

You can also provide an optional pathToPrivateKey parameter:

simulator.init(pathToPrivateKey);

Now you can generate a message with a single or multiple events:

const message = simulator.generateEvents(numberOfDataPoints);

Sending Messages

To send a single message to the server, call the sendSingleMessage method:

const res = simulator.sendSingleMessage();

To send messages at a specified interval, use the powerOn method:

simulator.powerOn(intervalInSec);

To stop sending messages, call the powerOff method:

simulator.powerOff();
1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.3.0

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.1

1 year ago