简体   繁体   English

如何在Node.js中异步接收Azure服务总线消息

[英]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.我在node.js中有socket.io,在.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.我正在将服务总线队列消息从socket.io发送到工作人员角色,而在工作人员角色中,我正在做一些处理,并通过服务总线队列将数据发送回socket.io。

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.但是我认为有时候socket.io会尝试接收比工作角色可发送的消息早一些的服务总线队列消息,因此,即使工作角色已发送了消息,socket.io也不会收到消息。

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.即使我已放置代码以在ReceivedMessage为空或接收消息时出错时再次接收消息,它也永远不会进入该部分。 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.在node.js中使用服务总线一直是一个真正的问题,因为我无法可靠地接收消息。 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.我在node.js中有socket.io,在.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.我正在将服务总线队列消息从socket.io发送到工作人员角色,而在工作人员角色中,我正在做一些处理,并通过服务总线队列将数据发送回socket.io。

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.但是我认为有时候socket.io会尝试接收比工作角色可发送的消息早一些的服务总线队列消息,因此,即使工作角色已发送了消息,socket.io也不会收到消息。

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.即使我已放置代码以在ReceivedMessage为空或接收消息时出错时再次接收消息,它也永远不会进入该部分。 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.在node.js中使用服务总线一直是一个真正的问题,因为我无法可靠地接收消息。 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.我在node.js中有socket.io,在.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.我正在将服务总线队列消息从socket.io发送到工作人员角色,而在工作人员角色中,我正在做一些处理,并通过服务总线队列将数据发送回socket.io。

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.但是我认为有时候socket.io会尝试接收比工作角色可发送的消息早一些的服务总线队列消息,因此,即使工作角色已发送了消息,socket.io也不会收到消息。

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.即使我已放置代码以在ReceivedMessage为空或接收消息时出错时再次接收消息,它也永远不会进入该部分。 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.在node.js中使用服务总线一直是一个真正的问题,因为我无法可靠地接收消息。 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.我在node.js中有socket.io,在.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.我正在将服务总线队列消息从socket.io发送到工作人员角色,而在工作人员角色中,我正在做一些处理,并通过服务总线队列将数据发送回socket.io。

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.但是我认为有时候socket.io会尝试接收比工作角色可发送的消息早一些的服务总线队列消息,因此,即使工作角色已发送了消息,socket.io也不会收到消息。

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.即使我已放置代码以在ReceivedMessage为空或接收消息时出错时再次接收消息,它也永远不会进入该部分。 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.在node.js中使用服务总线一直是一个真正的问题,因为我无法可靠地接收消息。 Please let me know if anyone has any solution or work around for this issue?请让我知道是否有人有任何解决方案或解决此问题?

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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