简体   繁体   中英

How to asynchronously receive a azure service bus message in node.js

I have socket.io in node.js and my worker role in .net. I am sending service bus queue message from socket.io to worker role and in worker role am doing some processing and sending data back to socket.io through the service bus queue.

But I think sometimes the socket.io tries to receive the service bus queue messages a bit earlier than the worker role can send and hence even though the worker role has sent the message, the socket.io doesnt receive it.

Below is my code :

function requestQueue(channelName) {

sleepTime[channelName] = 0;    

console.log("-------------------SEND to WORKER ROLE------------------------");

// send the request to worker role
var broadcastMessage = "somedata";    

sendMessage(socketToWorkerRole, broadcastMessage)

receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
}

// Sending service bus queue message

function sendMessage(queue, data) {   

serviceBusService.sendQueueMessage(queue, data, function (error) {
    if (!error) {
        console.log('Message sent....');
    }
})
}

// receiving service bus queue message

function receivePeriodicRecordsQueue(queue, channelName) {

serviceBusService.receiveQueueMessage(queue, function (error, receivedMessage) {
    if (!error) {
        if (receivedMessage != null) {        

            // some processing
        }
        else {
            console.log("---Service Bus Message is EMPTY-----");
            receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
        }
    }
    else {
        console.log(error);
        receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
    }
})

}

Even though I have put the code to receive the message again whenever the receivedMessage is empty or there is an error in receiving the message, it never comes into that section. It always just prints a custom message "No Messages to receive" in the console. Dunno where i can handle that.

It has been a real problem using the service bus in node.js because I havent been able to relaibly receive messages. Please let me know if anyone has any solution or work around for this issue?

Thanks

I have socket.io in node.js and my worker role in .net. I am sending service bus queue message from socket.io to worker role and in worker role am doing some processing and sending data back to socket.io through the service bus queue.

But I think sometimes the socket.io tries to receive the service bus queue messages a bit earlier than the worker role can send and hence even though the worker role has sent the message, the socket.io doesnt receive it.

Below is my code :

function requestQueue(channelName) {

sleepTime[channelName] = 0;    

console.log("-------------------SEND to WORKER ROLE------------------------");

// send the request to worker role
var broadcastMessage = "somedata";    

sendMessage(socketToWorkerRole, broadcastMessage)

receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
}

// Sending service bus queue message

function sendMessage(queue, data) {   

serviceBusService.sendQueueMessage(queue, data, function (error) {
    if (!error) {
        console.log('Message sent....');
    }
})
}

// receiving service bus queue message

function receivePeriodicRecordsQueue(queue, channelName) {

serviceBusService.receiveQueueMessage(queue, function (error, receivedMessage) {
    if (!error) {
        if (receivedMessage != null) {        

            // some processing
        }
        else {
            console.log("---Service Bus Message is EMPTY-----");
            receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
        }
    }
    else {
        console.log(error);
        receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
    }
})

}

Even though I have put the code to receive the message again whenever the receivedMessage is empty or there is an error in receiving the message, it never comes into that section. It always just prints a custom message "No Messages to receive" in the console. Dunno where i can handle that.

It has been a real problem using the service bus in node.js because I havent been able to relaibly receive messages. Please let me know if anyone has any solution or work around for this issue?

Thanks

I have socket.io in node.js and my worker role in .net. I am sending service bus queue message from socket.io to worker role and in worker role am doing some processing and sending data back to socket.io through the service bus queue.

But I think sometimes the socket.io tries to receive the service bus queue messages a bit earlier than the worker role can send and hence even though the worker role has sent the message, the socket.io doesnt receive it.

Below is my code :

function requestQueue(channelName) {

sleepTime[channelName] = 0;    

console.log("-------------------SEND to WORKER ROLE------------------------");

// send the request to worker role
var broadcastMessage = "somedata";    

sendMessage(socketToWorkerRole, broadcastMessage)

receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
}

// Sending service bus queue message

function sendMessage(queue, data) {   

serviceBusService.sendQueueMessage(queue, data, function (error) {
    if (!error) {
        console.log('Message sent....');
    }
})
}

// receiving service bus queue message

function receivePeriodicRecordsQueue(queue, channelName) {

serviceBusService.receiveQueueMessage(queue, function (error, receivedMessage) {
    if (!error) {
        if (receivedMessage != null) {        

            // some processing
        }
        else {
            console.log("---Service Bus Message is EMPTY-----");
            receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
        }
    }
    else {
        console.log(error);
        receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
    }
})

}

Even though I have put the code to receive the message again whenever the receivedMessage is empty or there is an error in receiving the message, it never comes into that section. It always just prints a custom message "No Messages to receive" in the console. Dunno where i can handle that.

It has been a real problem using the service bus in node.js because I havent been able to relaibly receive messages. Please let me know if anyone has any solution or work around for this issue?

Thanks

I have socket.io in node.js and my worker role in .net. I am sending service bus queue message from socket.io to worker role and in worker role am doing some processing and sending data back to socket.io through the service bus queue.

But I think sometimes the socket.io tries to receive the service bus queue messages a bit earlier than the worker role can send and hence even though the worker role has sent the message, the socket.io doesnt receive it.

Below is my code :

function requestQueue(channelName) {

sleepTime[channelName] = 0;    

console.log("-------------------SEND to WORKER ROLE------------------------");

// send the request to worker role
var broadcastMessage = "somedata";    

sendMessage(socketToWorkerRole, broadcastMessage)

receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
}

// Sending service bus queue message

function sendMessage(queue, data) {   

serviceBusService.sendQueueMessage(queue, data, function (error) {
    if (!error) {
        console.log('Message sent....');
    }
})
}

// receiving service bus queue message

function receivePeriodicRecordsQueue(queue, channelName) {

serviceBusService.receiveQueueMessage(queue, function (error, receivedMessage) {
    if (!error) {
        if (receivedMessage != null) {        

            // some processing
        }
        else {
            console.log("---Service Bus Message is EMPTY-----");
            receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
        }
    }
    else {
        console.log(error);
        receivePeriodicRecordsQueue(workerRoleToSocket, channelName);
    }
})

}

Even though I have put the code to receive the message again whenever the receivedMessage is empty or there is an error in receiving the message, it never comes into that section. It always just prints a custom message "No Messages to receive" in the console. Dunno where i can handle that.

It has been a real problem using the service bus in node.js because I havent been able to relaibly receive messages. Please let me know if anyone has any solution or work around for this issue?

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM