/// <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); } }
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."); } }
/// <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); }
/// <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, }); }
/// <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(); }
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."); } } }
/// <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(); }
public override async Task SetupAsync(WorkerContext context) { queue = context.CreateDistributedQueue <int>("sampleworker-testq"); }
public override async Task SetupAsync(WorkerContext context) { Console.WriteLine("Create DistributedQueue."); queue = context.CreateDistributedQueue <byte>("foo"); }