public void AddCachedRouting(string topic, RoutingInfo routing)
        {
            // the item we're going to cache
            CacheItem item = new CacheItem(topic, routing);

            // the policy that manages the item in cache
            CacheItemPolicy policy = new CacheItemPolicy();
            policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(_secondsUntilCacheExpires);

            lock (_cacheLock)
            {
                // the add call returns true if insertion succeeded, or false
                // if there is an already an entry in the cache that has the
                // same key as item.  But why would I care?  I don't want to
                // extend the cache time-to-live, so I'm happy with either.
                _cache.Add(item, policy);
            }
        }
Example #2
0
        public void GenerateJsonRoutingInfo()
        {
            RoutingInfo info = new RoutingInfo(new RouteInfo[] {
                new RouteInfo(
                    new Exchange("test-exchange-name", "test-host-1", "/test-vhost-1", 5727, "test-routing-key-1"),
                    new Exchange("test-exchange-name", "test-host-1", "/test-vhost-2", 5727, "test-routing-key-1")
                ),
                new RouteInfo(
                    new Exchange("test-exchange-2", "test-host-2", "/", 5727, "test-routing-key-2"),
                    new Exchange("test-exchange-2", "test-host-2", "/", 5727, "test-routing-key-2")
                )
            });

            using (StreamWriter writer = new StreamWriter(@"D:\projects\cmf-routing-info.txt"))
            {
                writer.WriteLine(JsonConvert.SerializeObject(info, Formatting.Indented));
                writer.Flush();
                writer.Close();
            }
        }