我有一些JavaScript代码通过使用2个不同的客户端对象来连接/订阅两个代理。我的问题是如何判断消息在onMessageArrived中从何而来。我收到消息,但我无法确定是哪个经纪人。有办法知道吗?
答案 0 :(得分:1)
你不能
解决方法是拥有3个onMessageArrived
函数:
client1.onMessageArrived = onMessageArrivedOne;
client2.onMessageArrived = onMessageArrivedTwo;
function onMessageArrivedOne(message) {
message.broker = 1;
onMessageArrived(message)
}
function onMessageArrivedTwo(message) {
message.broker = 2;
onMessageArrived(message)
}
function onMessageArrived(message) {
//do what you need
}