寻找AWS ElastiCache端点与Java [英] Finding AWS ElastiCache endpoints with Java

查看:367
本文介绍了寻找AWS ElastiCache端点与Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式获得ElastiCache端点从我的Java应用程序中使用最新的Java AWS SDK的列表。事情似乎并不奏效 - 我能找到一个有效的CacheCluster,但后来当我列出它的节点,它是空的。这是我的code:

I'm trying to programmatically get a list of ElastiCache endpoints from my Java app using the latest Java AWS SDK. Things don't seem to be working - I can find a valid CacheCluster, but then when I list its nodes, it's empty. Here's my code:

CacheCluster cc = it.next();

System.out.println("Cache node type: " + cc.getCacheNodeType());
System.out.println("Number cache nodes: " + cc.getNumCacheNodes());

List<CacheNode> listCache = cc.getCacheNodes();

System.out.println("List size: " + listCache.size());

当我运行它,我得到以下的输出:

When I run it, I get the following output:

Cache node type: cache.m1.small 
Number cache nodes: 1 
List size: 0

这看起来很简单,但似乎并没有工作。我已经开始与单个节点ElastiCache集群,但名单出现空当我打电话getCacheNodes()。我试图在一个EC2实例在本地并运行此code,我也得到了同样的事情两次。

This seems so simple, but doesn't seem to work. I have started an ElastiCache cluster with a single node, but the list comes up empty when I call getCacheNodes(). I've tried to run this code locally and on an EC2 instance, and I get the same thing both times.

这是什么,我可以做错了任何想法?

Any ideas on what I could be doing wrong?

推荐答案

据该AWS团队响应的不能够从ElastiCache集群高速缓存节点你的需要使用可选ShowDetails标志,以获得CacheNodes信息的通过<一href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/DescribeCacheClustersRequest.html">Class方法DescribeCacheClustersRequest 参数<一href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/AmazonElastiCacheClient.html#describeCacheClusters%28%29">describeCacheClusters().更仔细地观察有没有的 ShowDetails 的标志虽然,尽管被证明该类实际上:

According to the AWS team response to Not able to get cache nodes from ElastiCache cluster you'll need to use optional ShowDetails flag to obtain CacheNodes Information via the Class DescribeCacheClustersRequest parameter of method describeCacheClusters(). Looking closer there is no ShowDetails flag though, despite being documented for this class indeed:

这是可选的ShowDetails标志可用于检索详细   有关与缓存集群关联的Cache节点的信息。   详细信息包括高速缓存节点终端的DNS服务器地址和端口。

An optional ShowDetails flag can be used to retrieve detailed information about the Cache Nodes associated with the Cache Cluster. Details include the DNS address and port for the Cache Node endpoint.

presumably这实际上针对<一href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/DescribeCacheClustersRequest.html#setShowCacheNodeInfo%28java.lang.Boolean%29">setShowCacheNodeInfo(),其中的可选标志,可以包括在DescribeCacheCluster请求来检索高速缓存节点的信息

Presumably this actually targets setShowCacheNodeInfo(), which is An optional flag that can be included in the DescribeCacheCluster request to retrieve Cache Nodes information.

因此​​,AWS团队的反应似乎IM precise,实际上是不解决问题,为什么法<一个href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/CacheCluster.html#getCacheNodes%28%29">getCacheNodes()从<一个href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/CacheCluster.html">Class CacheCluster 没有返回的信息,均为pretty的不寻常的这样的帖子。

So the AWS team response seems imprecise and actually isn't addressing the question, why method getCacheNodes() from Class CacheCluster isn't returning that information, both being pretty unusual for such posts.

不管怎样,你可能只是想尝试的方法<一href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/CacheCluster.html#getCacheNodes%28%29">getCacheNodes()从<一个href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/CacheCluster.html">Class CacheCluster 中所返回的方法<一href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/DescribeCacheClustersResult.html#getCacheClusters%28%29">getCacheClusters()从<一个href="http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/elasticache/model/DescribeCacheClustersResult.html">Class DescribeCacheClustersResult 而是希望它可以作为做广告(即我没有尝试这样做我自己)。

Anyway, you might simply want to try method getCacheNodes() from Class CacheCluster as returned by method getCacheClusters() from Class DescribeCacheClustersResult instead, hopefully it works as advertized (i.e. I haven't tried this myself).

祝你好运!

下面是code桑德成功地用来实现他的目标,确认上面提到的方法:

Here is the code Sander used successfully to achieve his goal, confirming the approach outlined above:

AmazonElastiCacheClient client = new AmazonElastiCacheClient(credentials);
DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();
dccRequest.setShowCacheNodeInfo(true);

DescribeCacheClustersResult clusterResult = client.describeCacheClusters(dccRequest);

缺少的部分应类似于他最初的解决方案,例如:

The missing pieces should be similar to his initial solution, e.g.:

List<CacheCluster> cacheClusters = clusterResult.getCacheClusters();
for (CacheCluster cacheCluster : cacheClusters) {
    List<CacheNode> cacheNodes = cacheCluster.getCacheNodes();

    System.out.println("List size: " + cacheNodes.size());
}

这篇关于寻找AWS ElastiCache端点与Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆