本文介绍了天青,SubscriptionClient.OnMessage和会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否在Azure服务总线认购客户端支持使用的onMessage行动时的认购需要一个会话的能力吗?

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

我有一个订阅,被称为TestSubscription。它需要的sessionId和包含由一个SessionID的捆在一起的多部分数据

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);
}

在一个单独的项目中,我有一个服务总线监视器和WorkerRole,而在Worker角色,我有一个SubscriptionClient,叫testSubscriptionClient

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);

我随后将希望有的onMessage触发时新的数据项都放置在服务总线队列:

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

testSubscriptionClient.OnMessage(PersistData);

不过,我得到以下信息,当我运行code:

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

出现InvalidOperationException:这是不可能的,需要会话的实体创建一个非sessionful消息接收方

我使用的Azure SDK V2.8。

I am using Azure SDK v2.8.

就是我希望做的可能吗?是我需要我的服务总线监视器,使它可以让我以这种方式从认购检索邮件有特定的设置,订阅的客户,或其他地方。作为一个侧面说明,这种做法完全在我有在我没有使用sessioned数据的其他案件。

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.

推荐答案

你可以试试这个code:

Can you try this code:

var messageSession=testSubscriptionClient.AcceptMessageSession();

messageSession.OnMessage(PersistData);

这旁边:

testSubscriptionClient.OnMessage(PersistData);

编辑:
此外,您可以注册处理程序来处理会话( RegisterSessionHandler )。这将触发你天天看新动作。

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.

这篇关于天青,SubscriptionClient.OnMessage和会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 06:22