Error in receiving messages from Service Bus Queue
-
mercoledì 7 marzo 2012 05:15
Hi Everyone,
m having a weird exception when running the asychrous messaging from Service Bus Examples (ServiceBus_Samples_-_October_2011_Release). The weird part is im getting this error when trying to receive more than 2000 messages in a single queue.
Can anyone help me identify what is causing me the exception.
"Error during communication with service bus. Check the connection information, then retry."
Code from the example : AsyncMessaging solution..
//--------------------------------------------------------------------------------- // Copyright (c) 2011, Microsoft Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //--------------------------------------------------------------------------------- namespace Microsoft.Samples.AsyncMessaging { using System; using System.Threading; using Microsoft.ServiceBus; using Microsoft.ServiceBus.Messaging; public class AsyncReceiver { const string QueueName = "IssueTrackingQueue"; static string ServiceNamespace; static string IssuerName; static string IssuerKey; static void Main(string[] args) { GetUserCredentials(); TokenProvider credentials = TokenProvider.CreateSharedSecretTokenProvider(AsyncReceiver.IssuerName, AsyncReceiver.IssuerKey); Uri serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", AsyncReceiver.ServiceNamespace, string.Empty); MessagingFactory factory = null; try { //***************************************************************************************************** // Management Operations //***************************************************************************************************** NamespaceManager namespaceClient = new NamespaceManager(serviceUri, credentials); if (namespaceClient == null) { Console.WriteLine("\nUnexpected Error: NamespaceManager is NULL"); return; } //Retreive details of the queue QueueDescription queueDescription = namespaceClient.GetQueue(AsyncReceiver.QueueName); if (queueDescription == null) { Console.WriteLine("\nUnexpected Error: QueueDescription is NULL"); return; } //***************************************************************************************************** // Runtime Operations //***************************************************************************************************** factory = MessagingFactory.Create(serviceUri, credentials); QueueClient myQueueClient = factory.CreateQueueClient(AsyncReceiver.QueueName, ReceiveMode.PeekLock); //***************************************************************************************************** // Receiving messages from a Queue //***************************************************************************************************** Console.WriteLine("\nReceiving messages from Queue '{0}'...", AsyncReceiver.QueueName); // Retreive the number of messages currently in the Queue long messageCount = queueDescription.MessageCount; // Initiate the Asynchronous Receive using BeginReceive() call to receive the messages. for (long count = 0; count < messageCount; count++) { myQueueClient.BeginReceive(TimeSpan.FromSeconds(30), OnMessageReceive, myQueueClient); } Console.WriteLine("\nAfter all messages are received, press ENTER to exit."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine("Unexpected exception {0}", e.ToString()); throw; } finally { // Closing factory close all entities created from the factory. if (factory != null) { factory.Close(); } } } static void GetUserCredentials() { Console.Write("Please provide the service namespace to use: "); ServiceNamespace = Console.ReadLine(); Console.Write("Please provide the issuer name to use: "); IssuerName = Console.ReadLine(); Console.Write("Please provide the issuer key to use: "); IssuerKey = Console.ReadLine(); } public static void OnMessageReceive(IAsyncResult result) { QueueClient queueClient = (QueueClient) result.AsyncState ; try { //Receive the message with the EndReceive call BrokeredMessage message = queueClient.EndReceive(result); if (message != null) { Console.WriteLine("\nMessage Received: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>()); // The following is necessary in PeekLock Receive mode only. // Complete the message asynchronously. message.BeginComplete(OnMessageComplete, message); } else { Console.WriteLine("OnMessageReceive: Unexpected Error, Did not receive any messages"); } } catch (Exception e) { Console.WriteLine("OnMessageReceive: Unexpected exception in {0}", e.ToString()); throw; } } public static void OnMessageComplete(IAsyncResult result) { BrokeredMessage message = (BrokeredMessage) result.AsyncState ; // Signal the Completion of the Asynchronous Message Receive. try { message.EndComplete(result); Console.WriteLine("\nAsynchronous Message Receive Completed for Id = {0}", message.MessageId); } catch (Exception e) { Console.WriteLine("OnMessageComplete: Unexpected exception {0}", e.ToString()); throw; } } } }
See Stack Trace:
Server stack trace: at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndReceiveCommand(IAsyncResult result, IEnumerable`1& messages) at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.ReceiveAsyncResult.<GetAsyncSteps>b__35(ReceiveAsyncResult thisPtr, IAsyncResult a) at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result) Exception rethrown at [0]: at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult) at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.OnEndTryReceive(IAsyncResult result, IEnumerable`1& messages) at Microsoft.ServiceBus.Messaging.MessageReceiver.EndTryReceive(IAsyncResult result, IEnumerable`1& messages) at Microsoft.ServiceBus.Messaging.MessageReceiver.EndReceive(IAsyncResult result) at Microsoft.ServiceBus.Messaging.QueueClient.EndReceive(IAsyncResult result) at Microsoft.Samples.AsyncMessaging.AsyncReceiver.OnMessageReceive(IAsyncResult result) in C:\Users\aec\Desktop\ServiceBus_Samples_-_October_2011_Release\ServiceBus\CSharp\ExploringFeatures\BrokeredMessaging\AsyncMessaging\AsyncReceiver\AsyncReceiver.cs:line 163 at Microsoft.ServiceBus.Common.AsyncResult.Complete(Boolean didCompleteSynchronously)
Best Regards, Juan Genaro
- Modificato Juan Genaro mercoledì 7 marzo 2012 05:15
Tutte le risposte
-
mercoledì 7 marzo 2012 10:59Moderatore
Hi juan,
I have tested this service bus sample in my machine, but unfortunately i can not reproduce your problems, i modify the Sender.cs file as below:
for (int i = 0; i < 2000; i++) { messageList.Add(CreateIssueMessage(i.ToString(), "message" + i.ToString() + " information")); }If you run Sender and Receiver application at the same time, Receiver will get the current queues in Servicebus, but Receiver does not receive other messages in time, but your can still get them in the next time.
I can not even search your error message in Internet, have your ever modify anything with this sample? If so, please provide these messages and help us to solve it.
Thank you.
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
-
mercoledì 7 marzo 2012 13:59
Hi Juan,
Are you in a network where you have a firewall or an ISA Server that might be doing things with the connection?
Sandrino
-
giovedì 8 marzo 2012 02:53
Hi Arwind,
Thanks for investigating, I was able to solve this by creating multiple queues. I dont know whats the reason behind, but I saw it in Sandrino's response to one of my question http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/ffd2a668-75b9-46ed-b7b6-db12cb9886bf/#e965af31-ac33-49e4-a6b0-ecfba7331e79 (detailing best practices in using service bus).
@Sandrino
Yes, Im connected in a network, however I'm not sure if we have ISA installed here (still need to find out). :)
Best Regards, Juan Genaro
-
giovedì 8 marzo 2012 08:42Moderatore
Hi Juan,
I think Sandrino's opinion is Receiver can get 2000 messages per second, not "receive more than 2000 messages in a single queue." And i have tested this sample with 2500 messages in a single queue, it works fine at my side, do you met this error message only once or not (Try to test this sample for several times).
I think this error happens with your connection environment, it looks not like a Service Bus Queue limitation.
Hope it can help you.
Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework
- Contrassegnato come risposta Arwind - MSFTModerator mercoledì 14 marzo 2012 03:10

