How to get all the session id of a queue in azure service bus .Net CoreChoosing between .NET Service Bus Queues vs Azure Queue ServiceService Bus MessageSession accepted but Receive returns nullUsing WebJobs with Azure Service Bus and SessionsSubscriptionClient.AcceptMessageSession Faiiled with Timeout exceptionDifference between completing azure service bus queue with or without Session ID in Logic AppAzure Service Bus IQueueClient.registerSessionHandler: Unable to consume messages continuously from Queue/TopicDevelop and deploy App service of type API app in Azure using .net core web application projectGetting “amqp:internal-error” when peeking messages from Azure Service Bus Queue using AMQP, rhea and NodeAzure Service Bus Queue: Can I manage/cancel scheduled messages?Azure ServiceBus message from .net core does not parse in .net 4.6.1

My 15 year old son is gay. How do I express my feelings about this?

Where does an unaligned creature's soul go after death?

Worms crawling under skin

Why are there two fundamental laws of logic?

Where are they calling from?

Idiom for "I came, I saw, I ate" (or drank)

What causes the traces to wrinkle like this and should I be worried

Is It Possible to Have Different Sea Levels, Eventually Causing New Landforms to Appear?

What is the meaning of "heutig" in this sentence?

Can Northern Ireland's border issue be solved by repartition?

Is it true that, "just ten trading days represent 63 per cent of the returns of the past 50 years"?

What's the story to "WotC gave up on fixing Polymorph"?

In a folk jam session, when asked which key my non-transposing chromatic instrument (like a violin) is in, what do I answer?

Does the Orange League not count as an official Pokemon League, making the Alolan League his first-ever win?

Did Apollo carry and use WD40?

Writing a letter of recommendation for a mediocre student

Algorithm that spans orthogonal vectors: Python

If an object moving in a circle experiences centripetal force, then doesn't it also experience centrifugal force, because of Newton's third law?

Is it impolite to ask for halal food when traveling to and in Thailand?

Why does NASA publish all the results/data it gets?

Cut a cake into 3 equal portions with only a knife

The quicker I go up, the sooner I’ll go down - Riddle

Hiking with a mule or two?

What are the benefits and disadvantages if a creature has multiple tails, e.g., Kyuubi or Nekomata?



How to get all the session id of a queue in azure service bus .Net Core


Choosing between .NET Service Bus Queues vs Azure Queue ServiceService Bus MessageSession accepted but Receive returns nullUsing WebJobs with Azure Service Bus and SessionsSubscriptionClient.AcceptMessageSession Faiiled with Timeout exceptionDifference between completing azure service bus queue with or without Session ID in Logic AppAzure Service Bus IQueueClient.registerSessionHandler: Unable to consume messages continuously from Queue/TopicDevelop and deploy App service of type API app in Azure using .net core web application projectGetting “amqp:internal-error” when peeking messages from Azure Service Bus Queue using AMQP, rhea and NodeAzure Service Bus Queue: Can I manage/cancel scheduled messages?Azure ServiceBus message from .net core does not parse in .net 4.6.1






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















i'm making a web application which is connected to Azure by using .Net Core 2.1.1. I encountered some problem related with service bus queue when i'm trying to get the sessionid of the related queue.



I found some code, but it isn't supported by the .Net Core. Here below is the code:



var queueClient = QueueClient.CreateFromConnectionString(AppSettings.ServiceBusConnection, queueName);
var sessions = await queueClient.GetMessageSessionsAsync();
return sessions;


I also already tried this function,



var connString = Configuration.GetConnectionString("servicebus");
sessionClient = new SessionClient(connString, queue,ReceiveMode.PeekLock);
List<IMessageSession> sessions=new List<IMessageSession>();
while (true)

var session = await sessionClient.AcceptMessageSessionAsync();
if (session == null)
break;
sessions.Add(session);

return sessions;
}


But it keep giving me Timeout Exception. Can anyone help me ?










share|improve this question
































    0















    i'm making a web application which is connected to Azure by using .Net Core 2.1.1. I encountered some problem related with service bus queue when i'm trying to get the sessionid of the related queue.



    I found some code, but it isn't supported by the .Net Core. Here below is the code:



    var queueClient = QueueClient.CreateFromConnectionString(AppSettings.ServiceBusConnection, queueName);
    var sessions = await queueClient.GetMessageSessionsAsync();
    return sessions;


    I also already tried this function,



    var connString = Configuration.GetConnectionString("servicebus");
    sessionClient = new SessionClient(connString, queue,ReceiveMode.PeekLock);
    List<IMessageSession> sessions=new List<IMessageSession>();
    while (true)

    var session = await sessionClient.AcceptMessageSessionAsync();
    if (session == null)
    break;
    sessions.Add(session);

    return sessions;
    }


    But it keep giving me Timeout Exception. Can anyone help me ?










    share|improve this question




























      0












      0








      0








      i'm making a web application which is connected to Azure by using .Net Core 2.1.1. I encountered some problem related with service bus queue when i'm trying to get the sessionid of the related queue.



      I found some code, but it isn't supported by the .Net Core. Here below is the code:



      var queueClient = QueueClient.CreateFromConnectionString(AppSettings.ServiceBusConnection, queueName);
      var sessions = await queueClient.GetMessageSessionsAsync();
      return sessions;


      I also already tried this function,



      var connString = Configuration.GetConnectionString("servicebus");
      sessionClient = new SessionClient(connString, queue,ReceiveMode.PeekLock);
      List<IMessageSession> sessions=new List<IMessageSession>();
      while (true)

      var session = await sessionClient.AcceptMessageSessionAsync();
      if (session == null)
      break;
      sessions.Add(session);

      return sessions;
      }


      But it keep giving me Timeout Exception. Can anyone help me ?










      share|improve this question
















      i'm making a web application which is connected to Azure by using .Net Core 2.1.1. I encountered some problem related with service bus queue when i'm trying to get the sessionid of the related queue.



      I found some code, but it isn't supported by the .Net Core. Here below is the code:



      var queueClient = QueueClient.CreateFromConnectionString(AppSettings.ServiceBusConnection, queueName);
      var sessions = await queueClient.GetMessageSessionsAsync();
      return sessions;


      I also already tried this function,



      var connString = Configuration.GetConnectionString("servicebus");
      sessionClient = new SessionClient(connString, queue,ReceiveMode.PeekLock);
      List<IMessageSession> sessions=new List<IMessageSession>();
      while (true)

      var session = await sessionClient.AcceptMessageSessionAsync();
      if (session == null)
      break;
      sessions.Add(session);

      return sessions;
      }


      But it keep giving me Timeout Exception. Can anyone help me ?







      azure asp.net-core azureservicebus azure-servicebus-queues






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 5:30









      Joey Cai

      7,6251 gold badge3 silver badges12 bronze badges




      7,6251 gold badge3 silver badges12 bronze badges










      asked Mar 28 at 16:12









      gotokuryugagotokuryuga

      82 bronze badges




      82 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0
















          This is something which i tried and it worked for me, Please check the screenshot below



          enter image description here



          Here is the code i have tried



          using System;

          namespace Core.SBConsole

          using Microsoft.Azure.ServiceBus;
          using Microsoft.Azure.ServiceBus.Core;
          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Threading.Tasks;

          class Program

          // Connection String for the namespace can be obtained from the Azure portal under the
          // 'Shared Access policies' section.
          const string ServiceBusConnectionString = "Connection String";
          const string QueueName = "mvq";
          static IMessageSender messageSender;
          static ISessionClient sessionClient;
          const string SessionPrefix = "session-prefix";

          static void Main(string[] args)

          MainAsync().GetAwaiter().GetResult();


          static async Task MainAsync()

          const int numberOfSessions = 5;
          const int numberOfMessagesPerSession = 3;

          messageSender = new MessageSender(ServiceBusConnectionString, QueueName);
          sessionClient = new SessionClient(ServiceBusConnectionString, QueueName);

          // Send messages with sessionId set
          await SendSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          // Receive all Session based messages using SessionClient
          await ReceiveSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          Console.WriteLine("=========================================================");
          Console.WriteLine("Completed Receiving all messages... Press any key to exit");
          Console.WriteLine("=========================================================");

          Console.ReadKey();

          await messageSender.CloseAsync();
          await sessionClient.CloseAsync();


          static async Task ReceiveSessionMessagesAsync(int numberOfSessions, int messagesPerSession)

          Console.WriteLine("===================================================================");
          Console.WriteLine("Accepting sessions in the reverse order of sends for demo purposes");
          Console.WriteLine("===================================================================");

          for (int i = 0; i < numberOfSessions; i++)

          int messagesReceivedPerSession = 0;

          // AcceptMessageSessionAsync(i.ToString()) as below with session id as parameter will try to get a session with that sessionId.
          // AcceptMessageSessionAsync() without any messages will try to get any available session with messages associated with that session.
          IMessageSession session = await sessionClient.AcceptMessageSessionAsync();// (SessionPrefix + i.ToString());

          if (session != null)

          // Messages within a session will always arrive in order.
          Console.WriteLine("=====================================");
          Console.WriteLine($"Received Session: session.SessionId");

          while (messagesReceivedPerSession++ < messagesPerSession)

          Message message = await session.ReceiveAsync();

          Console.WriteLine($"Received message: SequenceNumber:message.SystemProperties.SequenceNumber Body:Encoding.UTF8.GetString(message.Body)");

          // Complete the message so that it is not received again.
          // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
          await session.CompleteAsync(message.SystemProperties.LockToken);


          Console.WriteLine($"Received all messages for Session: session.SessionId");
          Console.WriteLine("=====================================");

          // Close the Session after receiving all messages from the session
          await session.CloseAsync();




          static async Task SendSessionMessagesAsync(int numberOfSessions, int messagesPerSession)





          Things to consider before creating queue



          1) Make sure service bus is not in the free or basic tier, if yes then scale it to Standadrd



          2) Make sure to enable session while creating queue.



          I am using Microsoft.Azure.ServiceBus nuget pakcage 3.4 which is latest now.If you are using some other package try to upgrade/downgrade it.



          Hope it helps.






          share|improve this answer

























          • Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

            – gotokuryuga
            Mar 29 at 14:26











          • Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

            – Mohit Verma
            Mar 29 at 15:25












          • maybe there is some reason behind this problem

            – gotokuryuga
            Apr 1 at 7:09













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402281%2fhow-to-get-all-the-session-id-of-a-queue-in-azure-service-bus-net-core%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0
















          This is something which i tried and it worked for me, Please check the screenshot below



          enter image description here



          Here is the code i have tried



          using System;

          namespace Core.SBConsole

          using Microsoft.Azure.ServiceBus;
          using Microsoft.Azure.ServiceBus.Core;
          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Threading.Tasks;

          class Program

          // Connection String for the namespace can be obtained from the Azure portal under the
          // 'Shared Access policies' section.
          const string ServiceBusConnectionString = "Connection String";
          const string QueueName = "mvq";
          static IMessageSender messageSender;
          static ISessionClient sessionClient;
          const string SessionPrefix = "session-prefix";

          static void Main(string[] args)

          MainAsync().GetAwaiter().GetResult();


          static async Task MainAsync()

          const int numberOfSessions = 5;
          const int numberOfMessagesPerSession = 3;

          messageSender = new MessageSender(ServiceBusConnectionString, QueueName);
          sessionClient = new SessionClient(ServiceBusConnectionString, QueueName);

          // Send messages with sessionId set
          await SendSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          // Receive all Session based messages using SessionClient
          await ReceiveSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          Console.WriteLine("=========================================================");
          Console.WriteLine("Completed Receiving all messages... Press any key to exit");
          Console.WriteLine("=========================================================");

          Console.ReadKey();

          await messageSender.CloseAsync();
          await sessionClient.CloseAsync();


          static async Task ReceiveSessionMessagesAsync(int numberOfSessions, int messagesPerSession)

          Console.WriteLine("===================================================================");
          Console.WriteLine("Accepting sessions in the reverse order of sends for demo purposes");
          Console.WriteLine("===================================================================");

          for (int i = 0; i < numberOfSessions; i++)

          int messagesReceivedPerSession = 0;

          // AcceptMessageSessionAsync(i.ToString()) as below with session id as parameter will try to get a session with that sessionId.
          // AcceptMessageSessionAsync() without any messages will try to get any available session with messages associated with that session.
          IMessageSession session = await sessionClient.AcceptMessageSessionAsync();// (SessionPrefix + i.ToString());

          if (session != null)

          // Messages within a session will always arrive in order.
          Console.WriteLine("=====================================");
          Console.WriteLine($"Received Session: session.SessionId");

          while (messagesReceivedPerSession++ < messagesPerSession)

          Message message = await session.ReceiveAsync();

          Console.WriteLine($"Received message: SequenceNumber:message.SystemProperties.SequenceNumber Body:Encoding.UTF8.GetString(message.Body)");

          // Complete the message so that it is not received again.
          // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
          await session.CompleteAsync(message.SystemProperties.LockToken);


          Console.WriteLine($"Received all messages for Session: session.SessionId");
          Console.WriteLine("=====================================");

          // Close the Session after receiving all messages from the session
          await session.CloseAsync();




          static async Task SendSessionMessagesAsync(int numberOfSessions, int messagesPerSession)





          Things to consider before creating queue



          1) Make sure service bus is not in the free or basic tier, if yes then scale it to Standadrd



          2) Make sure to enable session while creating queue.



          I am using Microsoft.Azure.ServiceBus nuget pakcage 3.4 which is latest now.If you are using some other package try to upgrade/downgrade it.



          Hope it helps.






          share|improve this answer

























          • Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

            – gotokuryuga
            Mar 29 at 14:26











          • Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

            – Mohit Verma
            Mar 29 at 15:25












          • maybe there is some reason behind this problem

            – gotokuryuga
            Apr 1 at 7:09















          0
















          This is something which i tried and it worked for me, Please check the screenshot below



          enter image description here



          Here is the code i have tried



          using System;

          namespace Core.SBConsole

          using Microsoft.Azure.ServiceBus;
          using Microsoft.Azure.ServiceBus.Core;
          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Threading.Tasks;

          class Program

          // Connection String for the namespace can be obtained from the Azure portal under the
          // 'Shared Access policies' section.
          const string ServiceBusConnectionString = "Connection String";
          const string QueueName = "mvq";
          static IMessageSender messageSender;
          static ISessionClient sessionClient;
          const string SessionPrefix = "session-prefix";

          static void Main(string[] args)

          MainAsync().GetAwaiter().GetResult();


          static async Task MainAsync()

          const int numberOfSessions = 5;
          const int numberOfMessagesPerSession = 3;

          messageSender = new MessageSender(ServiceBusConnectionString, QueueName);
          sessionClient = new SessionClient(ServiceBusConnectionString, QueueName);

          // Send messages with sessionId set
          await SendSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          // Receive all Session based messages using SessionClient
          await ReceiveSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          Console.WriteLine("=========================================================");
          Console.WriteLine("Completed Receiving all messages... Press any key to exit");
          Console.WriteLine("=========================================================");

          Console.ReadKey();

          await messageSender.CloseAsync();
          await sessionClient.CloseAsync();


          static async Task ReceiveSessionMessagesAsync(int numberOfSessions, int messagesPerSession)

          Console.WriteLine("===================================================================");
          Console.WriteLine("Accepting sessions in the reverse order of sends for demo purposes");
          Console.WriteLine("===================================================================");

          for (int i = 0; i < numberOfSessions; i++)

          int messagesReceivedPerSession = 0;

          // AcceptMessageSessionAsync(i.ToString()) as below with session id as parameter will try to get a session with that sessionId.
          // AcceptMessageSessionAsync() without any messages will try to get any available session with messages associated with that session.
          IMessageSession session = await sessionClient.AcceptMessageSessionAsync();// (SessionPrefix + i.ToString());

          if (session != null)

          // Messages within a session will always arrive in order.
          Console.WriteLine("=====================================");
          Console.WriteLine($"Received Session: session.SessionId");

          while (messagesReceivedPerSession++ < messagesPerSession)

          Message message = await session.ReceiveAsync();

          Console.WriteLine($"Received message: SequenceNumber:message.SystemProperties.SequenceNumber Body:Encoding.UTF8.GetString(message.Body)");

          // Complete the message so that it is not received again.
          // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
          await session.CompleteAsync(message.SystemProperties.LockToken);


          Console.WriteLine($"Received all messages for Session: session.SessionId");
          Console.WriteLine("=====================================");

          // Close the Session after receiving all messages from the session
          await session.CloseAsync();




          static async Task SendSessionMessagesAsync(int numberOfSessions, int messagesPerSession)





          Things to consider before creating queue



          1) Make sure service bus is not in the free or basic tier, if yes then scale it to Standadrd



          2) Make sure to enable session while creating queue.



          I am using Microsoft.Azure.ServiceBus nuget pakcage 3.4 which is latest now.If you are using some other package try to upgrade/downgrade it.



          Hope it helps.






          share|improve this answer

























          • Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

            – gotokuryuga
            Mar 29 at 14:26











          • Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

            – Mohit Verma
            Mar 29 at 15:25












          • maybe there is some reason behind this problem

            – gotokuryuga
            Apr 1 at 7:09













          0














          0










          0









          This is something which i tried and it worked for me, Please check the screenshot below



          enter image description here



          Here is the code i have tried



          using System;

          namespace Core.SBConsole

          using Microsoft.Azure.ServiceBus;
          using Microsoft.Azure.ServiceBus.Core;
          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Threading.Tasks;

          class Program

          // Connection String for the namespace can be obtained from the Azure portal under the
          // 'Shared Access policies' section.
          const string ServiceBusConnectionString = "Connection String";
          const string QueueName = "mvq";
          static IMessageSender messageSender;
          static ISessionClient sessionClient;
          const string SessionPrefix = "session-prefix";

          static void Main(string[] args)

          MainAsync().GetAwaiter().GetResult();


          static async Task MainAsync()

          const int numberOfSessions = 5;
          const int numberOfMessagesPerSession = 3;

          messageSender = new MessageSender(ServiceBusConnectionString, QueueName);
          sessionClient = new SessionClient(ServiceBusConnectionString, QueueName);

          // Send messages with sessionId set
          await SendSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          // Receive all Session based messages using SessionClient
          await ReceiveSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          Console.WriteLine("=========================================================");
          Console.WriteLine("Completed Receiving all messages... Press any key to exit");
          Console.WriteLine("=========================================================");

          Console.ReadKey();

          await messageSender.CloseAsync();
          await sessionClient.CloseAsync();


          static async Task ReceiveSessionMessagesAsync(int numberOfSessions, int messagesPerSession)

          Console.WriteLine("===================================================================");
          Console.WriteLine("Accepting sessions in the reverse order of sends for demo purposes");
          Console.WriteLine("===================================================================");

          for (int i = 0; i < numberOfSessions; i++)

          int messagesReceivedPerSession = 0;

          // AcceptMessageSessionAsync(i.ToString()) as below with session id as parameter will try to get a session with that sessionId.
          // AcceptMessageSessionAsync() without any messages will try to get any available session with messages associated with that session.
          IMessageSession session = await sessionClient.AcceptMessageSessionAsync();// (SessionPrefix + i.ToString());

          if (session != null)

          // Messages within a session will always arrive in order.
          Console.WriteLine("=====================================");
          Console.WriteLine($"Received Session: session.SessionId");

          while (messagesReceivedPerSession++ < messagesPerSession)

          Message message = await session.ReceiveAsync();

          Console.WriteLine($"Received message: SequenceNumber:message.SystemProperties.SequenceNumber Body:Encoding.UTF8.GetString(message.Body)");

          // Complete the message so that it is not received again.
          // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
          await session.CompleteAsync(message.SystemProperties.LockToken);


          Console.WriteLine($"Received all messages for Session: session.SessionId");
          Console.WriteLine("=====================================");

          // Close the Session after receiving all messages from the session
          await session.CloseAsync();




          static async Task SendSessionMessagesAsync(int numberOfSessions, int messagesPerSession)





          Things to consider before creating queue



          1) Make sure service bus is not in the free or basic tier, if yes then scale it to Standadrd



          2) Make sure to enable session while creating queue.



          I am using Microsoft.Azure.ServiceBus nuget pakcage 3.4 which is latest now.If you are using some other package try to upgrade/downgrade it.



          Hope it helps.






          share|improve this answer













          This is something which i tried and it worked for me, Please check the screenshot below



          enter image description here



          Here is the code i have tried



          using System;

          namespace Core.SBConsole

          using Microsoft.Azure.ServiceBus;
          using Microsoft.Azure.ServiceBus.Core;
          using System;
          using System.Collections.Generic;
          using System.Text;
          using System.Threading.Tasks;

          class Program

          // Connection String for the namespace can be obtained from the Azure portal under the
          // 'Shared Access policies' section.
          const string ServiceBusConnectionString = "Connection String";
          const string QueueName = "mvq";
          static IMessageSender messageSender;
          static ISessionClient sessionClient;
          const string SessionPrefix = "session-prefix";

          static void Main(string[] args)

          MainAsync().GetAwaiter().GetResult();


          static async Task MainAsync()

          const int numberOfSessions = 5;
          const int numberOfMessagesPerSession = 3;

          messageSender = new MessageSender(ServiceBusConnectionString, QueueName);
          sessionClient = new SessionClient(ServiceBusConnectionString, QueueName);

          // Send messages with sessionId set
          await SendSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          // Receive all Session based messages using SessionClient
          await ReceiveSessionMessagesAsync(numberOfSessions, numberOfMessagesPerSession);

          Console.WriteLine("=========================================================");
          Console.WriteLine("Completed Receiving all messages... Press any key to exit");
          Console.WriteLine("=========================================================");

          Console.ReadKey();

          await messageSender.CloseAsync();
          await sessionClient.CloseAsync();


          static async Task ReceiveSessionMessagesAsync(int numberOfSessions, int messagesPerSession)

          Console.WriteLine("===================================================================");
          Console.WriteLine("Accepting sessions in the reverse order of sends for demo purposes");
          Console.WriteLine("===================================================================");

          for (int i = 0; i < numberOfSessions; i++)

          int messagesReceivedPerSession = 0;

          // AcceptMessageSessionAsync(i.ToString()) as below with session id as parameter will try to get a session with that sessionId.
          // AcceptMessageSessionAsync() without any messages will try to get any available session with messages associated with that session.
          IMessageSession session = await sessionClient.AcceptMessageSessionAsync();// (SessionPrefix + i.ToString());

          if (session != null)

          // Messages within a session will always arrive in order.
          Console.WriteLine("=====================================");
          Console.WriteLine($"Received Session: session.SessionId");

          while (messagesReceivedPerSession++ < messagesPerSession)

          Message message = await session.ReceiveAsync();

          Console.WriteLine($"Received message: SequenceNumber:message.SystemProperties.SequenceNumber Body:Encoding.UTF8.GetString(message.Body)");

          // Complete the message so that it is not received again.
          // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
          await session.CompleteAsync(message.SystemProperties.LockToken);


          Console.WriteLine($"Received all messages for Session: session.SessionId");
          Console.WriteLine("=====================================");

          // Close the Session after receiving all messages from the session
          await session.CloseAsync();




          static async Task SendSessionMessagesAsync(int numberOfSessions, int messagesPerSession)





          Things to consider before creating queue



          1) Make sure service bus is not in the free or basic tier, if yes then scale it to Standadrd



          2) Make sure to enable session while creating queue.



          I am using Microsoft.Azure.ServiceBus nuget pakcage 3.4 which is latest now.If you are using some other package try to upgrade/downgrade it.



          Hope it helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 29 at 10:12









          Mohit VermaMohit Verma

          3,2742 gold badges6 silver badges20 bronze badges




          3,2742 gold badges6 silver badges20 bronze badges















          • Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

            – gotokuryuga
            Mar 29 at 14:26











          • Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

            – Mohit Verma
            Mar 29 at 15:25












          • maybe there is some reason behind this problem

            – gotokuryuga
            Apr 1 at 7:09

















          • Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

            – gotokuryuga
            Mar 29 at 14:26











          • Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

            – Mohit Verma
            Mar 29 at 15:25












          • maybe there is some reason behind this problem

            – gotokuryuga
            Apr 1 at 7:09
















          Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

          – gotokuryuga
          Mar 29 at 14:26





          Hi! Thank you for the feedback. I tried your code and it works perfectly. The strange thing is when i implement it to my code, it doesn't work and only give me the Timeout Exception again. I already check the queue, and it's already enable session and also i'm using package 3.4 on Standard tier.

          – gotokuryuga
          Mar 29 at 14:26













          Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

          – Mohit Verma
          Mar 29 at 15:25






          Try to replicate the same behaviour while creating session client object which i have given in my sample.also please accept the answer if it helped. It will others in the community who are looking for same answer.

          – Mohit Verma
          Mar 29 at 15:25














          maybe there is some reason behind this problem

          – gotokuryuga
          Apr 1 at 7:09





          maybe there is some reason behind this problem

          – gotokuryuga
          Apr 1 at 7:09




















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55402281%2fhow-to-get-all-the-session-id-of-a-queue-in-azure-service-bus-net-core%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript