Download pool/shard000/JavaScript/0000133_pubsub.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/JavaScript/0000133_pubsub.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard000/JavaScript/0000133_pubsub.js
-
curl -L -o 0000133_pubsub.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/JavaScript/0000133_pubsub.js
1.84 kB
| /*jslint node: true */ | |
| ; | |
| var amqplib = require('amqplib'); | |
| var debug = require('debug')('hatchet.io-rabbitmq:pubsub'); | |
| var when = require('when'); | |
| function publishMessage(channel, message, amqpConf){ | |
| amqplib.connect(amqpConf.url).then(function(conn){ | |
| return when(conn.createChannel().then(function(ch){ | |
| ch.assertQueue(channel, amqpConf.queueOpts); | |
| ch.assertExchange(amqpConf.exchange.name, amqpConf.exchange.type, amqpConf.exchange.opts); | |
| ch.publish(amqpConf.exchange.name, channel, new Buffer(JSON.stringify(message))); | |
| debug('publishMessage', channel, message); | |
| return ch.close(); | |
| })).ensure(function(){ | |
| return conn.close(); | |
| }); | |
| }).then(null, function(error){ | |
| console.log('publisher amqp error', error); | |
| }); | |
| } | |
| function subscribeToChannel(channel, amqpConf, handleReceivedMessage){ | |
| amqplib.connect(amqpConf.url).then(function(conn) { | |
| process.once('SIGINT', function() { | |
| conn.close(); | |
| process.exit(); | |
| }); | |
| conn.createChannel().then(function(ch){ | |
| ch.assertQueue(channel, amqpConf.queueOpts); | |
| ch.assertExchange(amqpConf.exchange.name, amqpConf.exchange.type, amqpConf.exchange.opts); | |
| ch.bindQueue(channel, amqpConf.exchange.name, '*'); | |
| console.log('[*] Waiting for messages on ' + channel + '. To exit press CTRL+C'); | |
| ch.consume(channel, function(msg) { | |
| if (msg !== null) { | |
| ch.ack(msg); | |
| debug('subscribeToChannel', channel, msg); | |
| var receivedObject = JSON.parse(msg.content.toString()); | |
| handleReceivedMessage(channel, receivedObject); | |
| } | |
| }); | |
| }).then(null, function(error){ | |
| console.log('subscribeTo amqp error', error); | |
| }); | |
| }); | |
| } | |
| module.exports = { | |
| publishMessage: publishMessage, | |
| subscribeToChannel: subscribeToChannel | |
| }; | |