diff --git a/examples/device/amqp/publisher.ts b/examples/device/amqp/publisher.ts index 884ca87..90cbadd 100644 --- a/examples/device/amqp/publisher.ts +++ b/examples/device/amqp/publisher.ts @@ -2,7 +2,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; import { promisify } from 'util'; -import { AmqpClient } from '../../../src/index'; +import { AmqpClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/device/amqp/receiver.ts b/examples/device/amqp/receiver.ts index 2161bdf..c9d573f 100644 --- a/examples/device/amqp/receiver.ts +++ b/examples/device/amqp/receiver.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; -import { AmqpClient } from '../../../src/index'; +import { AmqpClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/device/mqtt/publisher.ts b/examples/device/mqtt/publisher.ts index d4de7d6..6ccdbb2 100644 --- a/examples/device/mqtt/publisher.ts +++ b/examples/device/mqtt/publisher.ts @@ -2,7 +2,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; import { promisify } from 'util'; -import { MqttClient } from '../../../src/index'; +import { MqttClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/device/mqtt/receiver.ts b/examples/device/mqtt/receiver.ts index cd29aa6..8d1771f 100644 --- a/examples/device/mqtt/receiver.ts +++ b/examples/device/mqtt/receiver.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; -import { MqttClient } from '../../../src/index'; +import { MqttClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/device/stomp/receiver.ts b/examples/device/stomp/receiver.ts index f839bfd..df3a775 100644 --- a/examples/device/stomp/receiver.ts +++ b/examples/device/stomp/receiver.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; -import { StompClient } from '../../../src/index'; +import { StompClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/stream/amqp/streamer.ts b/examples/stream/amqp/streamer.ts index ec8dcc7..2530fc9 100644 --- a/examples/stream/amqp/streamer.ts +++ b/examples/stream/amqp/streamer.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; -import { AmqpStreamClient } from '../../../src/index'; +import { AmqpStreamClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/stream/mqtt/streamer.ts b/examples/stream/mqtt/streamer.ts index a0ec386..e2174fb 100644 --- a/examples/stream/mqtt/streamer.ts +++ b/examples/stream/mqtt/streamer.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv'; import minimist from 'minimist'; -import { MqttStreamClient } from '../../../src/index'; +import { MqttStreamClient } from '../../../src/indexNode'; import { ISpaceBunnyParams } from '../../../src/spacebunny'; dotenv.config(); diff --git a/examples/stream/stomp/streamer.ts b/examples/stream/stomp/streamer.ts new file mode 100644 index 0000000..202b177 --- /dev/null +++ b/examples/stream/stomp/streamer.ts @@ -0,0 +1,68 @@ +import dotenv from 'dotenv'; + +import { StompStreamClient } from '../../../src/indexNode'; + +const args = require('minimist')(process.argv.slice(2)); + +dotenv.config(); + +// callback called when a message is received +const messageCallback = (content) => { + console.log(content); // eslint-disable-line no-console +}; + +// Auto Config +// You can also provide the endpointUrl to use a different end point, default is http://api.demo.spacebunny.io +const connectionParams = { + client: args['client'] || process.env.CLIENT || 'your-client-id', + secret: args['secret'] || process.env.SECRET || 'your-secret', +}; + +// Auto Config with tls +// You can also provide the endpointUrl to use a different end point, default is http://api.demo.spacebunny.io +// const connectionParams = { +// client: 'your-client-id', +// secret: 'your-secret', +// tls: true, +// ca: '/path/to/ca_certificate.pem', +// cert: '/path/to/client_certificate.pem', +// key: '/path/to/client_key.pem' +// }; + +// Manual Config +// const connectionParams = { +// client: 'your-client-id', +// secret: 'your-secret', +// host: 'host', +// port: 61613, // default for MQTT +// vhost: 'vhost' +// }; + +// Stream hooks contains the stream name from which you want to collect data +// and the callback which is invoked when receiving a message on that stream +// the boolean cache option can be passed to specify the stream connection mode. +// +// Options: +// stream: represents the stream name +// cache: (default true) +// true (or missing) means that you want to read messages from the stream cache +// false means that you want to read messages in a temporary queue that will be delete on disconnect + +const stream = args['stream'] || process.env.STREAM || ''; +const streams = Array.isArray(stream) ? stream : [stream]; +const streamHooks = []; +for (const streamName of streams) { + streamHooks.push({ stream: streamName, callback: messageCallback }); +} + +(async () => { + const streamClient = new StompStreamClient(connectionParams); + + await streamClient.connect(); + + try { + await streamClient.streamFrom(streamHooks) + } catch (error) { + console.error(error); + } +})()