我正在尝试使用REST从浏览器中读取Azure Service Bus主题订阅的替代方法。似乎SignalR对此很自然,但我似乎无法找到任何已经完成它的人。我不是在谈论横向扩展,只是一个SignalR Hub,它会将一组Service Bus功能来回传递给浏览器。我正在考虑像这样的功能(
addReceiver(string topic, string subscriptionID);
defineSubscription(string name, string subscriptionRule);
deleteSubscription(string name);
postMessageToTopic(string topic, string message);
addReceiver会在订阅上启动异步接收。每次从Service Bus获得消息时,都会在JS客户端上调用一个函数。
答案 0 :(得分:2)
这里有一些代码可以指出人们正确的方向。
namespace SBTester
{
public class SBHub : Hub
{
public void AddReceiver(string topic, string subscriptionName, string subscriptionFilter)
{
string messageData;
TopicConnector.Initialize( topic,
Context.ConnectionId + "." + subscriptionName,
subscriptionFilter);
// Initiate receive loop on Service Bus
TopicConnector.SBClient.OnMessage((receivedMessage) =>
{
try
{
// Process the message
messageData = receivedMessage.GetBody<string>();
Clients.Caller.onMessage(topic, messageData);
}
catch
{
// Handle any message processing specific exceptions here
}
});
}
public void DefineSubscription(string topic, string subscriptionRule)
{
// Call Service Bus to create Subscription on the Specified topic
}
public void PostMessageToTopic(string topic, string message)
{
// Call Service Bus to send a message
Clients.All.addNewMessageToPage(topic, message);
}
}
}
答案 1 :(得分:0)
从您的Hub代码中,您可以直接调用Service Bus API来发送消息或直接使用来自JavaScript /浏览器的Service Bus API:http://developers.de/blogs/damir_dobric/archive/2014/03/27/microsoft-azure-service-bus-receiving-of-messages-from-queue-and-topic-with-javascript.aspx