コード例 #1
0
        public void ConfigTest()
        {
            // The url below is used to bypass the .cfg. contraint of the hostname for testing locally
            ClusterConfigSettings settings = new ClusterConfigSettings("www.cfg.org", 11211);

            settings.NodeFactory = new NodeFactory();
            config = new ElastiCacheClusterConfig(loggerFactory, settings);
            this.config.DiscoveryNode.Dispose();
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: jonathansiqueira/GP
        public void ConfigureServices(IServiceCollection services)
        {
            ILoggerFactory loggerFactory = new LoggerFactory().AddConsole();

            services.AddSingleton <ILoggerFactory>(loggerFactory);
            services.AddLogging();
            services.AddTransient <IQueue, SQSWrapper>();
            services.AddTransient <INotifier, SNSWrapper>();
            services.AddTransient <IProductAnalyticsAPIClient, ProductAnalyticsAPIClient>();
            services.AddTransient <IHeadtoHeadAPIClient, HeadtoHeadAPIClient>();
            services.AddTransient <ICache, CachePersister>();
            services.AddTransient <IUDRData, UDRAPIClient>();
            services.AddTransient <IHttpClientFactory, HttpClientFactory>();
            IEncryptedEnvVariable encryptedEnvVariable = new EncryptedEnvVariable();

            services.AddSingleton <IEncryptedEnvVariable>(encryptedEnvVariable);
            services.AddMemoryCache();

            services.AddOptions();

            services.Configure <PingSettingsOptions>(o =>
            {
                o.PingAPIUrl       = Environment.GetEnvironmentVariable("OauthUrl");
                o.ClientID         = Environment.GetEnvironmentVariable("ServiceClientID");
                o.ClientSecret     = encryptedEnvVariable.DecodeEnvVarAsync("ServiceClientSecret").Result;
                o.PingTokenTimeout = TimeSpan.FromHours(Double.Parse(Environment.GetEnvironmentVariable("TokenTimeoutHoursDecimal")));
            });

            services.AddTransient <IPingSettings, PingSettings>();
            services.AddTransient <IOAuthClient, PingIDClient>();

            services.Configure <SlackAPIOptions>(o =>
            {
                o.SlackAppName    = Environment.GetEnvironmentVariable("SlackAppName");
                o.SlackWebhookUrl = Environment.GetEnvironmentVariable("SlackWebhookUrl");
            });
            services.AddSingleton <ISlackAPI, SlackAPI>();

            var builder = new ConfigurationBuilder()
                          .AddEnvironmentVariables();

            IConfiguration        Configuration = builder.Build();
            IConfigurationSection serverSection = Configuration.GetSection("enyimMemcached_cfgserver");
            IConfigurationSection portSection   = Configuration.GetSection("enyimMemcached_port");

            services.AddTransient <IMemcachedClient, MemcachedClient>((IServiceProvider) =>
            {
                var config = new ElastiCacheClusterConfig(serverSection.Value, Int32.Parse(portSection.Value));
                return(new MemcachedClient(loggerFactory, config));
            });
        }
コード例 #3
0
        /// <summary>
        /// The node used to discover endpoints in an ElastiCache cluster
        /// </summary>
        /// <param name="config">The config of the client to access the SocketPool</param>
        /// <param name="hostname">The host name of the cluster with .cfg. in name</param>
        /// <param name="port">The port of the cluster</param>
        /// <param name="tries">The number of tries for requesting config info</param>
        /// <param name="delay">The time, in miliseconds, to wait between tries</param>
        internal DiscoveryNode(ElastiCacheClusterConfig config, string hostname, int port, int tries, int delay)
        {
            #region Param Checks

            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrEmpty(hostname))
            {
                throw new ArgumentNullException("hostname");
            }
            if (port <= 0)
            {
                throw new ArgumentException("Port cannot be 0 or less");
            }
            if (tries < 1)
            {
                throw new ArgumentException("Must atleast try once");
            }
            if (delay < 0)
            {
                throw new ArgumentException("The delay can't be negative");
            }
            if (hostname.IndexOf(".cfg", StringComparison.OrdinalIgnoreCase) < 0)
            {
                throw new ArgumentException("The hostname is not able to use Auto Discovery");
            }

            #endregion

            #region Setting Members

            this.hostname       = hostname;
            this.port           = port;
            this.config         = config;
            this.ClusterVersion = 0;
            this.tries          = tries;
            this.delay          = delay;

            this.clusterLock  = new Object();
            this.endpointLock = new Object();
            this.nodesLock    = new Object();

            #endregion

            this.ResolveEndPoint();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            // instantiate a new client.
            ElastiCacheClusterConfig config    = new ElastiCacheClusterConfig();
            MemcachedClient          memClient = new MemcachedClient(config);

            // Store the data for 3600 seconds (1hour) in the cluster.
            // The client will decide which cache host will store this item.
            memClient.Store(StoreMode.Set, "mykey", "This is the data value.", TimeSpan.FromMinutes(10));

            var mykey = memClient.Get <string>("mykey");



            Console.ReadLine();
        }
コード例 #5
0
        /// <summary>
        /// Creates a server pool for auto discovery
        /// </summary>
        /// <param name="configuration">The client configuration using the pool</param>
        /// <param name="opFactory">The factory used to create operations on demand</param>
        public AutoServerPool(ElastiCacheClusterConfig configuration, IOperationFactory opFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("socketConfig");
            }
            if (opFactory == null)
            {
                throw new ArgumentNullException("opFactory");
            }

            this.configuration = configuration;
            this.factory       = opFactory;

            this.deadTimeoutMsec = (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds;
        }
コード例 #6
0
        public void InitialRequestTest()
        {
            // The url below is used to bypass the .cfg. contraint of the hostname for testing locally
            ClusterConfigSettings settings = new ClusterConfigSettings("www.cfg.org", 11211);

            settings.NodeFactory = new NodeFactory();
            config = new ElastiCacheClusterConfig(loggerFactory, settings);

            client = new MemcachedClient(loggerFactory, config);

            Assert.AreEqual(new Version("1.4.14"), config.DiscoveryNode.NodeVersion);
            Assert.AreEqual(1, config.DiscoveryNode.ClusterVersion);
            Assert.AreEqual(3, config.DiscoveryNode.NodesInCluster);

            this.config.DiscoveryNode.Dispose();
            client.Dispose();
        }
コード例 #7
0
        public void PollerTesting()
        {
            //Poller is set to poll every second to make this test faster
            ClusterConfigSettings settings = new ClusterConfigSettings("www.cfg.org", 11211);

            settings.NodeFactory = new NodeFactory();
            settings.ClusterPoller.IntervalDelay = 1000;
            config = new ElastiCacheClusterConfig(settings);

            client = new MemcachedClient(config);

            // Buffer time to wait, this can fail occasionally because delays can occur in the poller or timer
            System.Threading.Thread.Sleep(3000);
            Assert.AreEqual(3, config.DiscoveryNode.ClusterVersion);
            Assert.AreEqual(1, config.DiscoveryNode.NodesInCluster);

            this.config.DiscoveryNode.Dispose();
            client.Dispose();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Creating config...");
                ElastiCacheClusterConfig config = new ElastiCacheClusterConfig("mexicotest.9s71yv.0001.use2.cache.amazonaws.com", 6379);

                Console.WriteLine("Creating client...");
                MemcachedClient client = new MemcachedClient(config);

                if (client.Store(Enyim.Caching.Memcached.StoreMode.Set, "Demo", "Hello World"))
                {
                    Console.WriteLine("Stored to cache successfully");
                }
                else
                {
                    Console.WriteLine("Did not store to cache successfully");
                }

                Object value;
                if (client.TryGet("Demo", out value))
                {
                    Console.WriteLine("Got the value: " + (value as string));
                }
                else
                {
                    // Search Database if the get fails
                    Console.WriteLine("Checking database because get failed");
                }

                Console.Read();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
コード例 #9
0
        private void ButtonOlder_Click(object sender, EventArgs e)
        {
            try
            {
                this.LabelStatus.Text = "Instantiating";

                // Instantiates client with default settings and uses the hostname and port provided
                this.config = new ElastiCacheClusterConfig(this.TextOlder.Text, Convert.ToInt32(this.TextPort.Text));

                this.mem = new MemcachedClient(this.config);

                #region UI Stuff

                this.TimerPoller.Enabled  = false;
                this.ProgressPoller.Value = 0;
                this.TimerPoller.Enabled  = true;

                if (mem == null)
                {
                    this.LabelStatus.Text = "MemcachedClient returned a null object";
                }
                else
                {
                    this.ButtonAdd.Enabled       = true;
                    this.ButtonGet.Enabled       = true;
                    this.LabelStatus.Text        = "Old Instantiation Success";
                    this.ProgressBarStatus.Value = 25;
                }

                #endregion
            }
            catch (Exception ex)
            {
                this.LabelStatus.Text = ex.Message;
            }
        }
コード例 #10
0
        private void ButtonInstantiate_Click(object sender, EventArgs e)
        {
            try
            {
                this.LabelStatus.Text = "Instantiating";

                // Instantiates config from app.config in the clusterclient section
                this.config = new ElastiCacheClusterConfig();

                mem = new MemcachedClient(this.config);

                #region UI Stuff

                this.TimerPoller.Enabled  = false;
                this.ProgressPoller.Value = 0;
                this.TimerPoller.Enabled  = true;

                if (mem == null)
                {
                    this.LabelStatus.Text = "MemcachedClient returned a null object";
                }
                else
                {
                    this.ButtonAdd.Enabled       = true;
                    this.ButtonGet.Enabled       = true;
                    this.LabelStatus.Text        = "Instantiation Success";
                    this.ProgressBarStatus.Value = 25;
                }

                #endregion
            }
            catch (Exception ex)
            {
                this.LabelStatus.Text = ex.Message;
            }
        }
コード例 #11
0
 /// <summary>
 /// The node used to discover endpoints in an ElastiCache cluster
 /// </summary>
 /// <param name="config">The config of the client to access the SocketPool</param>
 /// <param name="hostname">The host name of the cluster with .cfg. in name</param>
 /// <param name="port">The port of the cluster</param>
 internal DiscoveryNode(ElastiCacheClusterConfig config, string hostname, int port)
     : this(config, hostname, port, DEFAULT_TRY_COUNT, DEFAULT_TRY_DELAY)
 {
 }
 /// <summary>
 /// Creates a poller for Auto Discovery with the default intervals
 /// </summary>
 /// <param name="client">The memcached client to update servers for</param>
 public ConfigurationPoller(ElastiCacheClusterConfig config)
     : this(config, DEFAULT_INTERVAL_DELAY)
 {
 }
コード例 #13
0
 public Form1(ILoggerFactory loggerFactory, ElastiCacheClusterConfig config)
 {
     InitializeComponent();
     _loggerFactory = loggerFactory;
     _config        = config;
 }
コード例 #14
0
        public AutoBinaryPool(ElastiCacheClusterConfig configuration)
#if CORE_CLR
            : base(configuration, new BinaryOperationFactory(configuration.Logger))
#else
            : base(configuration, new BinaryOperationFactory())
コード例 #15
0
 /// <summary>
 /// Creates a MemcachedClient using the Client config provided
 /// </summary>
 /// <param name="config">The config to instantiate the client with</param>
 /// <returns>A new MemcachedClient configured for auto discovery</returns>
 public static MemcachedClient CreateClient(ILoggerFactory loggerFactory, ElastiCacheClusterConfig config)
 {
     return(new MemcachedClient(loggerFactory, config));
 }