const updateBalance = async () => { const balances = await getBalances(); redisClientMessageQueue.publish('facts', JSON.stringify({ bittrexAccountBalances: balances })); return balances; }
const getAccountValue = async () => { if (transactionLock) { // Only Compute account balances when a transaction is not in progress return false; } const account = new Account(); account.setBittrexBalance(sienaAccount.getBittrexBalanceObj()); const currentAccountValue = await account.getAccountValue(); redisClientMessageQueue.publish('facts', JSON.stringify({ principle, currentAccountValue })); return currentAccountValue; }
function redisHeartbeat(redisUrl, periodSecs) { // Setup Redis datastore to drive heartbeat const redisHeartbeat = redis.createClient(redisUrl); redisHeartbeat.on("error", function (err) { console.error(`redis heartbeat error: ${err.stack}`); process.exit(1); }); redisHeartbeat.publish('heartbeat', '💗'); setInterval(() => { redisHeartbeat.publish('heartbeat', '💗'); }, periodSecs * 1000); }
redisPub.on('connect', function () { console.log("Pub Connected to Redis Server " + HOST + ":" + PORT); redisPub.publish('all', JSON.stringify({ 'uuid': 'server', 'text': 'Hello from server' })); });
app.get('/', (req, res) => { publishClient.publish('REQUESTS', `Request on ${req.socket.localPort} for ${req.url}`); console.log(`Local log for ${req.url}`); });
// synchronize messages after redis reconnect between server instances function synchronize() { if (syncPointer != -1) { log.logMessage("verbose", "redis synchronization!"); var syncMessage = {}; syncMessage.data = messages.splice(syncPointer, messages.length - syncPointer); setTimeout(function () { pub.publish("message", JSON.stringify(syncMessage)); }, 200); syncPointer = -1; } }
sub.on('connect', function () { console.log("Sub Connected to Redis Server " + HOST + ":" + PORT); sub.subscribe(UUID + '_message_channel'); sub.subscribe(FRAME); sub.subscribe('all'); const timeoutFunction = function () { pub.publish('info', JSON.stringify({ uuid: UUID, text: "This message is sent from " + UUID })); setTimeout(timeoutFunction, 10000) } timeoutFunction(); });
setInterval(function() { i++; client.publish("channel_one", "I am sending a message #"+i); }, 1000);
wss.on("connection", ws => { console.log("Client connected"); ws.on("message", msg => { console.log(`Message: ${msg}`); // When a new message is received from a connected client, we publish a message in the chat_messages channel. // We don't directly broadcast the message to clients because the server is subscribed to the same channel // so it will come back to us through Redis. redisPub.publish("chat_messages", msg); }); });
//the server object listens on port 8080 setInterval(()=> { pub.publish(redisChannel, JSON.stringify({ from: 's1', to: 's2' })); }, 3000);
// synchronizes messages after redis reconnect between server Instances function synchronize() { if (syncPointer != -1) { log.logMessage("verbose", "redis synchronization!"); var syncMessage = {}; syncMessage.data = messages.splice(syncPointer, messages.length - syncPointer); setTimeout(function () { pub.publish("message", JSON.stringify(syncMessage)); }, 200); syncPointer = -1; } }
pub.on('connect', function () { console.log("Pub Connected to Redis Server " + HOST + ":" + PORT); pub.publish('auth', JSON.stringify({ 'uuid': UUID, 'text': 'Hello from edge device ' + UUID })); });