Commit 8ac40526 by zCaesar

fix message floor

parent a929e649
...@@ -9,14 +9,15 @@ function on_message_redis(deviceid, payload, topic) { // first time to access on ...@@ -9,14 +9,15 @@ function on_message_redis(deviceid, payload, topic) { // first time to access on
} }
else { else {
var information = setValue(deviceid, payload, topic) var information = setValue(deviceid, payload, topic)
console.log(information.total_message_size)
redis.hincrby(information.keys, 'actual_message_count', 1) redis.hincrby(information.keys, 'actual_message_count', 1)
redis.hincrby(information.keys, 'charged_message_count', information.charged_message_count) redis.hincrby(information.keys, 'charged_message_count', information.charged_message_count)
redis.hincrby(information.keys, 'total_message_size', information.total_message_size) redis.hincrby(information.keys, 'total_message_size', Math.floor(information.total_message_size))
redis.hincrby(setBrokerValue().keys, 'actual_message_count', 1) redis.hincrby(setBrokerValue().keys, 'actual_message_count', 1)
redis.hincrby(setBrokerValue().keys, 'charged_message_count', information.charged_message_count) redis.hincrby(setBrokerValue().keys, 'charged_message_count', information.charged_message_count)
redis.hincrby(setBrokerValue().keys, 'total_message_size', information.total_message_size) redis.hincrby(setBrokerValue().keys, 'total_message_size', Math.floor(information.total_message_size))
redis.hset(information.keys, 'last_publish', information.last_publish, function (err, res) { redis.hset(information.keys, 'last_publish', information.last_publish, function (err, res) {
resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1 resolve(!res) // 0 is ok, 1 is no => if ok is 0 then not 0 = 1
}) })
...@@ -30,6 +31,7 @@ function setValue(deviceid, payload, topic) { ...@@ -30,6 +31,7 @@ function setValue(deviceid, payload, topic) {
var keys = 'deviceid:' + deviceid var keys = 'deviceid:' + deviceid
var last_publish = dateNow var last_publish = dateNow
var total_message_size = (payload.length + topic.length) * (3 / 4) var total_message_size = (payload.length + topic.length) * (3 / 4)
console.log('total_message_size: ' + total_message_size)
var msg_count_size = total_message_size var msg_count_size = total_message_size
var charged_message_count = 1 var charged_message_count = 1
while (msg_count_size > 5000) { while (msg_count_size > 5000) {
......
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