1

Im trying to use elasticache as a memcache service with AWS's elasticache client library for java.

The following code works for connecting to the cluster:

_client = new MemcachedClient(_serverList);

But any attempt I've made to use consistent hashing results in memcache client failing to initialize:

_client = new MemcachedClient(new KetamaConnectionFactory(), _serverList);

or

ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
connectionFactoryBuilder.setLocatorType(Locator.CONSISTENT);
connectionFactoryBuilder.setHashAlg(DefaultHashAlgorithm.KETAMA_HASH);
connectionFactoryBuilder.setClientMode(ClientMode.Dynamic);
ConnectionFactory connectionFactory = connectionFactoryBuilder.build();
_client = new MemcachedClient(connectionFactory, _serverList);

Any attempt I've made to use anything but a vanilla MemcacheClient results in errors such as :

2015-04-07 07:00:32.914 WARN net.spy.memcached.ConfigurationPoller: The configuration is null in the server localhost 2015-04-07 07:00:32.914 WARN net.spy.memcached.ConfigurationPoller: Number of consecutive poller errors is 7. Number of minutes since the last successful polling is 0

Also, I've verified with telnet, spymecached libs, and the vanilla MemcacheClient constructor, that the security groups are permissive.

4

2 回答 2

3

使用 AWS 客户端库时,KetamaConnectionFactory默认为“动态”客户端模式,该模式尝试从配置端点轮询可用的 memcached 节点列表。为此,您_serverList应该只包含配置端点。

您的错误消息表明主机是不理解 ElastiCache 扩展的“普通”memcached 节点。如果这是您打算做的(自己指定节点而不是使用自动发现功能),那么您需要使用多参数KetamaConnectionFactory构造函数并ClientMode.Static作为第一个参数传入。

于 2015-10-14T14:51:08.387 回答
1

您将需要使用 AddrUtil.getAddresses() 方法。

_client = new MemcachedClient(new KetamaConnectionFactory(), AddrUtil.getAddresses("configEndpoint:port"));

或者

ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder(new KetamaConnectionFactory());
// set any other properties you want on the builder
ConnectionFactory connectionFactory = connectionFactoryBuilder.build();
_client = new MemcachedClient(connectionFactory, AddrUtil.getAddresses("configEndpoint:port"));
于 2015-04-07T16:06:21.523 回答