Unverified Commit b10a4f98 authored by Bennett Piater's avatar Bennett Piater
Browse files

start adapting enhance as trigger client

parent a0b974db
......@@ -3,20 +3,20 @@ const { Kafka, logLevel } = require('kafkajs')
async function writeToKafka(topic, key, json) {
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'],
clientId: 'enhancer',
brokers: ['kafka03-prod02.messagehub.services.eu-gb.bluemix.net:9093', 'kafka02-prod02.messagehub.services.eu-gb.bluemix.net:9093', 'kafka01-prod02.messagehub.services.eu-gb.bluemix.net:9093'],
ssl: true,
sasl: {
mechanism: 'scram-sha-256',
username: 'mra5q18k',
password: 'SddBJrfRgVWkWYCYhaw-J_5pDDDamZsS'
username: 'urGiSyjzBjRRNAHE',
password: 'rHICukLEqbSb9DIKrYmejTRRkMgDUkZK'
}
});
const producer = kafka.producer()
await producer.connect()
await producer.send({
topic: 'mra5q18k-' + topic,
topic: topic,
messages: [{
key: key,
value: json]
......@@ -26,21 +26,21 @@ async function writeToKafka(topic, key, json) {
return {};
}
function main({filename}) {
// TODO decide how data gets passed in
async function processImage(filename, data) {
const image = Buffer.from(data, "base64");
return new Promise((resolve, reject) => {
gm(image, "test.jpg")
// .contrast(-3)
.enhance()
.toBuffer((err, buffer) => {
if (err)
reject({ "error": err });
else {
writeToKafka("topic3", filename + ".enhanced.jpg", '{"data": "' + buffer.toString("base64") + '"}');
resolve({});
}
});
});
gm(image, "test.jpg")
// .contrast(-3)
.enhance()
.toBuffer((err, buffer) => {
if (err)
return;
writeToKafka("topic3", filename + ".enhanced.jpg", '{"data": "' + buffer.toString("base64") + '"}');
resolve({});
})
}
function main({messages}) {
messages.forEach(msg => processImage(msg.key, msg.value.data))
}
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