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)
- how to get the exact matched message which has same sessionId?
- whether any other feature is there apart from sessionId to achieve the same?
Thanks in Advance.