在 Java 中设置 Amazon ElastiCache w/spymemcached

发布于 2025-01-01 15:52:45 字数 2413 浏览 1 评论 0原文

我在 Amazon Cloud 上找不到关于 Memcached 的好教程,而且我对整个缓存事情还很陌生。 我正在尝试通过 Amazon 的 ElastiCache 服务使用 memcached 并使用间谍memcached 客户端来实际进行 memcached 调用。

这是我现在在 Java 中所做的事情:

try {
        ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
        MemcachedClient memcachedClient = new MemcachedClient(
                connectionFactoryBuilder.build(),
                AddrUtil.getAddresses("<beginning of cache node end point grabbed from AWS Console>.cache.amazonaws.com:11211"));
        memcachedClient.set("test", 12, new Integer(12));
        System.out.println(memcachedClient.get("test"));
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }

当我尝试此操作时出现的错误是:

java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:414)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:278)
at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:1981)
 2012-02-01 19:25:35.415 WARN net.spy.memcached.MemcachedConnection:  Closing, and        reopening {QA sa=<node endpoint>.cache.amazonaws.com/184.73.64.56:11211, #Rops=0, #Wops=2, #iq=0, topRop=null, topWop=net.spy.memcached.protocol.ascii.StoreOperationImpl@be8c3e, toWrite=0, interested=0}, attempt 1.
 net.spy.memcached.OperationTimeoutException: Timeout waiting for value
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1142)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1157)
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:117)
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:88)
at com.amazon.imaging.demo.DemoUI$4.run(DemoUI.java:368)
at com.amazon.imaging.demo.DemoUI.main(DemoUI.java:391)
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: <node endpoint>.cache.amazonaws.com/184.73.64.56:11211
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:65)
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:37)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1135)
... 5 more

有人对此有任何想法或经验吗? 谢谢!

I haven't been able to find a good tutorial on Memcached on Amazon Cloudand I'm very new to this whole caching thing.
I am trying to use memcached through Amazon's ElastiCache service and with a spymemcached client to actually make the memcached calls.

Here's what I'm doing in Java right now:

try {
        ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
        MemcachedClient memcachedClient = new MemcachedClient(
                connectionFactoryBuilder.build(),
                AddrUtil.getAddresses("<beginning of cache node end point grabbed from AWS Console>.cache.amazonaws.com:11211"));
        memcachedClient.set("test", 12, new Integer(12));
        System.out.println(memcachedClient.get("test"));
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }

The error that I get when I try this is:

java.net.ConnectException: Connection refused
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:414)
at net.spy.memcached.MemcachedConnection.handleIO(MemcachedConnection.java:278)
at net.spy.memcached.MemcachedClient.run(MemcachedClient.java:1981)
 2012-02-01 19:25:35.415 WARN net.spy.memcached.MemcachedConnection:  Closing, and        reopening {QA sa=<node endpoint>.cache.amazonaws.com/184.73.64.56:11211, #Rops=0, #Wops=2, #iq=0, topRop=null, topWop=net.spy.memcached.protocol.ascii.StoreOperationImpl@be8c3e, toWrite=0, interested=0}, attempt 1.
 net.spy.memcached.OperationTimeoutException: Timeout waiting for value
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1142)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1157)
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:117)
at com.amazon.imaging.demo.SQSQueueManager.requeue(SQSQueueManager.java:88)
at com.amazon.imaging.demo.DemoUI$4.run(DemoUI.java:368)
at com.amazon.imaging.demo.DemoUI.main(DemoUI.java:391)
Caused by: net.spy.memcached.internal.CheckedOperationTimeoutException: Timed out waiting for operation - failing node: <node endpoint>.cache.amazonaws.com/184.73.64.56:11211
at net.spy.memcached.internal.OperationFuture.get(OperationFuture.java:65)
at net.spy.memcached.internal.GetFuture.get(GetFuture.java:37)
at net.spy.memcached.MemcachedClient.get(MemcachedClient.java:1135)
... 5 more

Anyone got any ideas or experience with this?
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我恋#小黄人 2025-01-08 15:52:45

你在哪里执行这个?来自 EC2 实例中或来自外部网络。请记住,ElastiCache 服务器受安全组绑定,该安全组限制对 ElastiCAche 实例的访问。因此,请检查允许您连接到 Memcached 服务器的安全组和其他配置。据我所知,ElastiCache 无法从 AWS 边界外部访问。

其余代码看起来不错,c考虑使用 Spring 等框架来处理 memcache 客户端对象实例化和相关配置。

Where are you executing this? From with in a EC2 instance or from an external network. Remember that ElastiCache servers are bound by the security group which restricts the access to the ElastiCAche instances. So checkout the security group and other configurations that allow you to connect to the Memcached server. as far as I know, ElastiCache cannot be accessed from outside AWS boundary

Rest of the code looks fine and cConsider using a framework like Spring to handle the memcache client object instantiation and related configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文