-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducer.js
More file actions
25 lines (22 loc) · 813 Bytes
/
producer.js
File metadata and controls
25 lines (22 loc) · 813 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env node
const diffusion = require('diffusion');
const args = process.argv.slice(2);
if (args.length < 5) {
console.error(`wrong # args, try ${process.argv[1]} host principal credentials topic-path topic-value`);
process.exit(1);
}
const [host, principal, credentials, topicPath, topicValue] = args;
diffusion.connect({
host,
principal,
credentials,
}).then(session => {
const stringType = diffusion.datatypes.string();
const stringTopicSpec = new diffusion.topics.TopicSpecification(diffusion.topics.TopicType.STRING);
return session.topicUpdate.set(topicPath, stringType, topicValue, {specification: stringTopicSpec})
}).then(() => {
process.exit(0);
}).catch(error => {
console.error(`Cannot set ${topicPath} on ${host}: ${error}`);
process.exit(1);
})