2012-06-06 50 views
2

我想知道Kestrel是如何工作的,但即使在Java中使用它作爲庫,我也遇到了一些困難。紅隼指南/教程/文檔?

有人有鏈接或可以幫助我建立一個隊列嗎?

我發現this,但它不會對上次發佈工作..:/

回答

0

我有同樣的問題。我發現這個鏈接顯示了使用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。)

祝你好運!

0

我有同樣的問題。我最初使用xmemcached客戶端,但後來發現使用它簡單的包裝更容易使用。這包裝成了jestrel,這是可以在這裏下的Apache許可證:

https://github.com/cobbzilla/jestrel

我設計極致簡約的jestrel API。它已經在生產環境中測試並且性能良好。試試看,讓我知道你的想法。