I have been working on session enabled topic/subscription.
Used following code to create session enabled Topic/Subscription,
var subscriptionName = "TestSubscription";
var topicName = "MyPartitionTopic";
var namespaceManager = NamespaceManager.CreateFromConnectionString(RuntimeConfig.ConnectionStrings.PrimaryAzureSb);
if (!namespaceManager.TopicExists(topicName))
{
var td = new TopicDescription(topicName);
td.EnablePartitioning = true;
namespaceManager.CreateTopic(td);
}
if (!namespaceManager.SubscriptionExists(topicName, subscriptionName))
{
var sd = new SubscriptionDescription(topicName, subscriptionName);
sd.RequiresSession = true;
namespaceManager.CreateSubscription(sd);
}
While receiving message in Receiver, filtering based on sessionId is not happening. I have used following code in Receiver,
void ReadMessage(string ConnectionStrings, string topicName, string subscriptionName, MessagingFactory messagingFactory, int batchcount)
{
int receivedMessages = 0;
SubscriptionClient subsClient =
messagingFactory.CreateSubscriptionClient(topicName, subscriptionName, ReceiveMode.ReceiveAndDelete);
string sessionId = "sessionId1";
subsClient.AcceptMessageSession(sessionId);
IEnumerable<BrokeredMessage> messages = subsClient.PeekBatch(batchcount);
}
For example: I am sending message with following sessionId
Scenario 1 . sessionId = sessionId1
Scenario 2 . sessionId = sessionId2
Receiver:
Suppose I need to get messages which has only sessionId1,But using the above method it's simply returning the top batch of record(it may be sessionId1 or sessionId2)
Thanks in Advance.
The method you used
subscriptionClient.AcceptMessageSession()
will return messages with available sessions across all session-enabled subscriptions in the service namespace.
Use
subscriptionClient.OnAcceptSessionReceiver()
to receive message with a specific "sessionId".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.