示例#1
0
 /// <summary>
 /// displays queued objects
 /// </summary>
 /// <param name="distributedQueue">Queue to display</param>
 private void DisplayQueueData(IDistributedQueue <object> distributedQueue)
 {
     Console.WriteLine("Result count: " + distributedQueue.Count);
     foreach (Customer queueCustomer in distributedQueue)
     {
         Console.WriteLine("--");
         DisplayCustomerData(queueCustomer);
     }
 }
示例#2
0
        public void DistributedQueueNameTest()
        {
            using (var gridion = GridionFactory.Start())
            {
                IDistributedQueue <string> queue = gridion.GetQueue <string>("name");

                Assert.IsNotNull(queue, "queue != null");
                Assert.AreEqual("name", queue.Name, "The name is incorrect.");
            }
        }
示例#3
0
        /// <summary>
        /// Creates a distributed queue to which customers are to be added
        /// </summary>
        private static IDistributedQueue <Customer> GetOrCreateQueue()
        {
            IDistributedQueue <Customer> distributedQueue = _cache.DataTypeManager.GetQueue <Customer>(QueueName);

            if (distributedQueue == null)
            {
                DataTypeAttributes attributes = new DataTypeAttributes
                {
                    Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 1, 0))
                };

                // Creating distributed queue with absolute expiration of 1 minute
                distributedQueue = _cache.DataTypeManager.CreateQueue <Customer>(QueueName, attributes);
            }

            return(distributedQueue);
        }
示例#4
0
 /// <summary>
 /// Enqueue data to Queue. Similar methods for other data structures can be written in the same way
 /// </summary>
 /// <param name="distributedQueue"></param>
 private void AddDataToQueue(IDistributedQueue <object> distributedQueue)
 {
     distributedQueue.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName);
     InputDataFromUser();
     distributedQueue.Enqueue(new Customer()
     {
         CustomerID  = CustomerID,
         ContactName = ContactName,
         CompanyName = CompanyName,
         Address     = Address,
         City        = City,
         Country     = Country,
         PostalCode  = PostalCode,
         ContactNo   = Phone,
         Fax         = Fax,
     });
 }
示例#5
0
        /// <summary>
        /// Executing this method will perform all the operations of the sample
        /// </summary>
        public static void Run()
        {
            // Initialize cache
            InitializeCache();

            //Create or get a distributed queue by name
            _distributedQueue = GetOrCreateQueue();

            // Adding items to distributed queue
            Console.WriteLine("\n--- Enqueue Customers to Queue ---");
            EnqueueInQueue();
            Console.WriteLine();

            // Get the first object from distributed queue
            Console.WriteLine("\n--- Peek Customer From Queue ---");
            PeekFromQueue();
            Console.WriteLine();

            // Dequeue from distributed queue
            Console.WriteLine("\n--- Dequeue customer from Distributed Queue ---");
            DequeueFromQueue();
            Console.WriteLine();

            // Display customers from distributed queue
            Console.WriteLine("\n--- Display Customers From Queue ---");
            DisplayFromQueue(true);
            Console.WriteLine();

            // clear distributed queue
            Console.WriteLine("\n--- Clear Distributed Queue ---");
            ClearQueue();
            Console.WriteLine();

            // Remove the distributed queue from cache
            Console.WriteLine("\n--- Remove Distributed Queue from Cache --- ");
            DeleteQueueFromCache();
            Console.WriteLine();

            // Dispose the cache once done
            _cache.Dispose();
        }
示例#6
0
        public void DistributedQueueTest2Nodes()
        {
            var configuration  = new GridionConfiguration("127.0.0.1", 24000);
            var configuration2 = new GridionConfiguration("127.0.0.1", 24001);

            using (var gridion = GridionFactory.Start(configuration))
            {
                using (var gridion2 = GridionFactory.Start(configuration2))
                {
                    IDistributedQueue <string> queue = gridion.GetQueue <string>("name");

                    Assert.IsNotNull(queue, "queue != null");
                    Assert.AreEqual("name", queue.Name, "The name is incorrect.");

                    IDistributedQueue <string> queue2 = gridion2.GetQueue <string>("name");

                    Assert.IsNotNull(queue2, "queue != null");
                    Assert.AreEqual("name", queue2.Name, "The name is incorrect.");
                }
            }
        }
示例#7
0
 /// <summary>
 /// remove queue entry by Customer
 /// </summary>
 /// <param name="distributedList"></param>
 public void RemoveQueueValue(IDistributedQueue <object> distributedQueue)
 {
     distributedQueue.WriteThruOptions = new WriteThruOptions(WriteMode.WriteThru, WriteThruProviderName);
     distributedQueue.Dequeue();
 }
示例#8
0
文件: Worker.cs 项目: ttak0422/DFrame
 public override async Task SetupAsync(WorkerContext context)
 {
     queue = context.CreateDistributedQueue <int>("sampleworker-testq");
 }
示例#9
0
 public override async Task SetupAsync(WorkerContext context)
 {
     Console.WriteLine("Create DistributedQueue.");
     queue = context.CreateDistributedQueue <byte>("foo");
 }