Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoiani committed Jul 14, 2021
1 parent e126815 commit dcf1db2
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/device/amqp/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/amqp/receiver.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/mqtt/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/mqtt/receiver.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/device/stomp/receiver.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/stream/amqp/streamer.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/stream/mqtt/streamer.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
68 changes: 68 additions & 0 deletions examples/stream/stomp/streamer.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})()

0 comments on commit dcf1db2

Please sign in to comment.