首页 > 代码库 > kestrel用java来利用
kestrel用java来利用
kestrel用的是scala,java无法直接使用。如想用java来运行kestrel,需要利用Xmemcached库。
创建queue_kestrel.java
# cd
# mkdir test
# export source_dir=~/test
# vi queue_kestrel.java
-----------------------------------------------------
import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.command.KestrelCommandFactory;
import net.rubyeye.xmemcached.utils.AddrUtil;
public class queue_kestrel {
public static void main(String[] args) throws Exception {
XMemcachedClientBuilder builder=null;
MemcachedClient client=null;
int expirationTime=0;
String queueName="test";
String host="192.168.172.99";
String port = "22133";
builder=new XMemcachedClientBuilder(AddrUtil.getAddresses(host+":"+port));
builder.setCommandFactory(new KestrelCommandFactory());
try {
client=builder.build();
client.set(queueName,expirationTime,"hello");
String res=client.get(queueName);
System.out.println(res);
} catch (java.io.IOException e){}
}
}
----------------------------------------------------
准备必要的库。
xmemcached
# wget http://xmemcached.googlecode.com/files/xmemcached-1.3.7-bin-with-dependencies.tar.gz
# tar zxvf xmemcached-1.3.7-bin-with-dependencies.tar.gz
# cp xmemcached-1.3.7/xmemcached-1.3.7.jar xmemcached-1.3.7/lib/slf4j-api-1.5.7.jar $source_dir
slf4j
# wget http://www.slf4j.org/dist/slf4j-1.6.6.zip
# unzip slf4j-1.6.6.zip
# cp slf4j-1.6.6/slf4j-jdk14-1.6.6.jar $source_dir
kestrel
# cp /usr/local/kestrel/kestrel_2.9.1-2.2.0.jar $source_dir
运行
启动kestrel服务器。
# java -jar /usr/local/kestrel/kestrel_2.9.1-2.2.0.jar &
编译queue_kestrel.java并运行。
# cd $source_dir
# javac -cp ./xmemcached-1.3.7.jar:./slf4j-api-1.5.7.jar:./slf4j-jdk14-1.6.6.jar:./kestrel_2.9.1-2.2.0.jar: queue_kestrel.java
# java -cp ./xmemcached-1.3.7.jar:./slf4j-api-1.5.7.jar:./slf4j-jdk14-1.6.6.jar:./kestrel_2.9.1-2.2.0.jar: queue_kestrel
kestrel用java来利用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。