Azure, SubscriptionClient.OnMessage, and Sessions

笑着哭i 提交于 2019-12-11 10:52:10

问题


Does the Azure Service Bus Subscription client support the ability to use OnMessage Action when the subscription requires a session?

I have a subscription, called "TestSubscription". It requires a sessionId and contains multipart data that is tied together by a SessionId.

if (!namespaceManager.SubscriptionExists("TestTopic", "Export"))
{
    var testRule = new RuleDescription
    {
        Filter = new SqlFilter(@"(Action='Export')"),
        Name = "Export"
    };

var subDesc = new SubscriptionDescription("DataCollectionTopic", "Export")
{
    RequiresSession = true
};
namespaceManager.CreateSubscription(sub`enter code here`Desc, testRule);
}

In a seperate project, I have a Service Bus Monitor and WorkerRole, and in the Worker Role, I have a SubscriptionClient, called "testSubscriptionClient":

testSubscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, _topicName, CloudConfigurationManager.GetSetting("testSubscription"), ReceiveMode.PeekLock);

I would then like to have OnMessage triggered when new items are placed in the service bus queue:

testSubscriptionClient.OnMessage(PersistData);

However I get the following message when I run the code:

InvalidOperationException: It is not possible for an entity that requires sessions to create a non-sessionful message receiver

I am using Azure SDK v2.8.

Is what I am looking to do possible? Are there specific settings that I need to make in my service bus monitor, subscription client, or elsewhere that would let me retrieve messages from the subscription in this manner. As a side note, this approach works perfectly in other cases that I have in which I am not using sessioned data.


回答1:


Can you try this code:

var messageSession=testSubscriptionClient.AcceptMessageSession();

messageSession.OnMessage(PersistData);

beside of this:

testSubscriptionClient.OnMessage(PersistData);

Edit: Also, you can register your handler to handle sessions (RegisterSessionHandler). It will fire your handle every new action.

I think this is more suitable for your problem.

He shows both way, in this article. It's for queue, but I think you can apply this to topic also.



来源:https://stackoverflow.com/questions/36135960/azure-subscriptionclient-onmessage-and-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!