【问题标题】:Kestrel guide/tutorial/documentation?Kestrel 指南/教程/文档?
【发布时间】:2012-06-10 08:21:35
【问题描述】:

我试图了解 Kestrel 是如何工作的,但我什至无法在 Java 中找到一个使用它作为库的工作示例。

有人有链接或可以帮助我设置队列吗?

我找到了this,但它在最后一个版本上不起作用..:/

【问题讨论】:

    标签: java kestrel


    【解决方案1】:

    我遇到了同样的问题。我发现这个链接显示了一个使用 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。)

    祝你好运!

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。我最初使用的是 xmemcached 客户端,但后来发现使用简单的包装器更容易使用。该包装器变成了 jestrel,可在此处根据 Apache 许可证获得:

      https://github.com/cobbzilla/jestrel

      我设计 jestrel API 是为了非常简单。它已经在生产环境中进行了测试并且表现良好。试试看,让我知道你的想法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多