Failed to connect to AWS ElastiCache clusters using the Membase client library for memcached

I'm having trouble getting / set for an ElastiCache cluster from my EC2 instance. I get - SEVERE: net.spy.memcached.OperationTimeoutException: Timeout waiting for value - error.

When I try to get or set a value. I used the same code on my local machine (although I communicated with the local memcached server) and everything works fine. The full stack can be found here - http://pastebin.com/tYcCJ6cj

At first I saw that I can at least get the IP address of all the nodes in the cluster so that I can forward it to my membase client, and I can really find out the IP addresses of the node. I also made sure that all my EC2 security groups are added to the cluster security group by default.

Any pointers to this would be very helpful.

UPDATE

A snippet of code used to retrieve a specific entry.

 public String getCachedValue(String namespace, String key) { String value = null; try { MemcachedClient client = CacheConnectionUtil.connectToElastiCacheMemcachedServer(); // Point of origin for the exception. return (String) client.get(namespace + "$" + hashKey(key)); } catch (IOException e) { e.printStackTrace(); } return value; } 

Code snippet used to connect to ElastiCache server

 private static MemcachedClient connectToElastiCacheMemcachedServer() throws IOException { DescribeCacheClustersResult cacheClustersInfo = null; DescribeCacheClustersRequest cacheClusterRequest = new DescribeCacheClustersRequest(); cacheClusterRequest.setShowCacheNodeInfo(true); try { cacheClustersInfo = AWSConnectionUtil .getElastiCacheObject(null) .describeCacheClusters(cacheClusterRequest); } catch (Exception e) { e.printStackTrace(); throw new IOException("Unable to connect to ElastiCache Cluster.", e); } if (cacheClustersInfo == null) { throw new IOException("ElastiCache Cluster Info Object is null."); } List<CacheCluster> clusters = cacheClustersInfo.getCacheClusters(); if (clusters == null || clusters.isEmpty()) { throw new IOException("No ElastiCache Clusters available."); } List<String> serverList = new ArrayList<String>(); for (CacheCluster cluster : clusters) { if (cluster != null && AWSConstants .CACHE_CLUSTER_ID .equalsIgnoreCase(cluster.getCacheClusterId())) { List<CacheNode> nodes = cluster.getCacheNodes(); if (nodes != null ) { for (CacheNode node : nodes) { if (node != null) { Endpoint endpoint = node.getEndpoint(); if (endpoint != null && endpoint.getAddress() != null) { serverList.add(endpoint.getAddress() + ":" + endpoint.getPort()); } } } } } } if (serverList.isEmpty()) { throw new IOException("No Cached nodes available for cluster - " + AWSConstants.CACHE_CLUSTER_ID); } return new MemcachedClient(AddrUtil.getAddresses(serverList)); } 
+6
source share
1 answer

Use the modified Cluster ElastiCache client created by Amazon.

http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/AutoDiscovery.html#AutoDiscovery.ClusterClient

According to the documentation, to download the Cluster ElastiCache client:

The source code for the Cluster Client for ElastiCache for Java is available at https://github.com/amazonwebservices/aws-elasticache-cluster-client-memcached-for-java . This library is based on the popular Spymemcached client. Cluster ElastiCache Client is licensed under Amazon Software. You can modify the source code as you wish; you can even include code in other open source Memcached libraries or in your own client code.

Currently version 1.0.1. I have been using version 1.0 without any problems for over a year.

0
source

Source: https://habr.com/ru/post/901571/


All Articles