【发布时间】:2012-06-10 08:21:35
【问题描述】:
【问题讨论】:
【问题讨论】:
我遇到了同样的问题。我发现这个链接显示了一个使用 PHP 创建的客户端。我能够以此作为创建 Java 客户端的基础:http://blog.shupp.org/2011/05/07/getting-started-with-kestrel-from-a-php-application/
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import net.spy.memcached.MemcachedClient;
public class KestrelClient {
private MemcachedClient client = null;
private String kestrelHost = null;
private int kestrelPort = -1;
public KestrelClient(final String kestrelHost, final int kestrelPort)
{
this.kestrelHost = kestrelHost;
this.kestrelPort = kestrelPort;
try
{
this.client = new MemcachedClient(new InetSocketAddress(this.kestrelHost, this.kestrelPort));
}
catch (IOException e)
{
e.printStackTrace();
}
}
public boolean set(final String queueName, final int expiration, final Object data)
{
Future<Boolean> setFuture = this.client.set(queueName, expiration, data);
try
{
return setFuture.get().booleanValue();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
catch (ExecutionException e)
{
e.printStackTrace();
}
return false;
}
public Object reliableRead(final String queueName, final int timeout)
{
Object object = this.client.get(queueName + "/close/open/t=" + timeout);
closeReliableRead(queueName);
return object;
}
public void closeReliableRead(final String queueName)
{
this.client.get(queueName + "/close");
}
public void abortReliableRead(final String queueName)
{
this.client.get(queueName + "/abort");
}
}
它并不完美,但应该可以帮助您入门。 (依赖于 spymemcached。)
祝你好运!
【讨论】:
我遇到了同样的问题。我最初使用的是 xmemcached 客户端,但后来发现使用简单的包装器更容易使用。该包装器变成了 jestrel,可在此处根据 Apache 许可证获得:
https://github.com/cobbzilla/jestrel
我设计 jestrel API 是为了非常简单。它已经在生产环境中进行了测试并且表现良好。试试看,让我知道你的想法。
【讨论】: