Unverified Commit 6825c406 authored by Bennett Piater's avatar Bennett Piater
Browse files

start work on producer

parents
#!/bin/bash
set -e
wsk=$1
pushd $(dirname $0)/producer
zip -ru ../producer.zip * || true
popd
for i in {0..1}; do
$wsk -i action update producer$i $(dirname $0)/producer.zip --param id $i --kind nodejs:8
done
const { Kafka, logLevel } = require('kafkajs')
async function main({id}) {
const kafka = new Kafka({
clientId: 'producer',
brokers: ['ark-01.srvs.cloudkafka.com:9094', 'ark-02.srvs.cloudkafka.com:9094', 'ark-03.srvs.cloudkafka.com:9094'],
ssl: true,
sasl: {
mechanism: 'scram-sha-256',
username: 'mra5q18k',
password: 'SddBJrfRgVWkWYCYhaw-J_5pDDDamZsS'
}
});
let date = Date.now()
let value = Math.floor(Math.random() * 41)
const producer = kafka.producer()
await producer.connect()
await producer.send({
topic: 'mra5q18k-sensors',
messages: [{
key: null,
value: `{producer: ${id}, timestamp: ${date}, value: ${value}}`}]
})
await producer.disconnect()
return {};
}
exports.main = main;
{
"name": "producer",
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"kafkajs": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/kafkajs/-/kafkajs-1.4.4.tgz",
"integrity": "sha512-f+cYW9QSkCsThY5qlzAKTedF9WpyNq+mzGZF/4lx2OJwqFkOHyMaqXgp2ILcIJZ+8O7fo7uqxuH9ODoJqy5BfQ==",
"requires": {
"long": "^4.0.0"
},
"dependencies": {
"long": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/long/-/long-4.0.0.tgz",
"integrity": "sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA=="
}
}
}
}
}
{
"name": "producer",
"main": "index.js",
"dependencies": {
"kafkajs": "*"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment