/// <summary>
        ///     Begin listening for messages.
        /// </summary>
        public void Start()
        {
            if (_isStarted)
                throw new InvalidOperationException("AzureCommandBusListener have already been started.");
            _isStarted = true;

            _queueClient.BeginReceive(OnMessage, null);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Begin listening for messages.
        /// </summary>
        public void Start()
        {
            if (_isStarted)
            {
                throw new InvalidOperationException("AzureEventBusListener have already been started.");
            }
            _isStarted = true;

            _logger.Write(LogLevel.Info, "Starting");
            _queueClient.BeginReceive(OnMessage, null);
        }
        public override void Run()
        {
            while (!IsStopped)
            {
                // Increment Request Counter
                Interlocked.Increment(ref dequeueRequests);

                Trace.WriteLine(dequeueRequests + " request(s) in progress");

                Client.BeginReceive(new TimeSpan(0, 0, 10), ProcessUrgentEmails, Client);

                // If we have made too many requests, wait for them to finish before requesting again.
                while (dequeueRequests >= MaxThreads && !IsStopped)
                {
                    System.Diagnostics.Trace.WriteLine(dequeueRequests + " requests in progress, waiting before requesting more work");
                    Thread.Sleep(2000);
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            GetUserCredentials();

            MessagingFactory factory = null;

            try
            {
                //*****************************************************************************************************
                //                                   Management Operations
                //*****************************************************************************************************
                NamespaceManager namespaceClient = NamespaceManager.CreateFromConnectionString(ServiceBusConnectionString);
                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.CreateFromConnectionString(ServiceBusConnectionString);

                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();
                }
            }
        }
Ejemplo n.º 5
0
 public void Start()
 {
     _requestQueue.BeginReceive(OnMessage, null);
 }
Ejemplo n.º 6
0
 public void Start()
 {
     _queryQueueClient.BeginReceive(OnMessage, null);
 }