`
JavaCrazyer
  • 浏览: 3009587 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类

Kestrel队列使用示例[配置、安装、命令]

 
阅读更多

kestrel认知

1)Kestrel是twitter开源的一个scala写的简单高效MQ,采用的协议是memcached的文本协议,但是并不完全支持所有memcached协议,也不是完全兼容现有协议。

2)标准的协议它仅支持GET、SET、FLUSH_ALL、STATS,

3)Kestrel是一个队列服务器

 

使用示例

package com.wujintao.kestrel;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import org.junit.BeforeClass;
import org.junit.Test;

import net.rubyeye.xmemcached.MemcachedClient;
import net.rubyeye.xmemcached.MemcachedClientBuilder;
import net.rubyeye.xmemcached.XMemcachedClientBuilder;
import net.rubyeye.xmemcached.command.KestrelCommandFactory;
import net.rubyeye.xmemcached.exception.MemcachedException;
import net.rubyeye.xmemcached.utils.AddrUtil;
public class TestCase {
	private static MemcachedClient memcachedClient;
	private String ketrelQueueName = "abc";

	@BeforeClass
	public static void init() {
		MemcachedClientBuilder builder = new XMemcachedClientBuilder(
				AddrUtil.getAddresses("localhost:22133"));
		builder.setCommandFactory(new KestrelCommandFactory());
            /**
             * 设置连接池大小,即客户端个数
             * In a high concurrent enviroment,you may want to pool memcached clients.
             * But a xmemcached client has to start a reactor thread and some thread pools,
             * if you create too many clients,the cost is very large. 
             * Xmemcached supports connection pool instreadof client pool.
             * you can create more connections to one or more memcached servers,
             * and these connections share the same reactor and thread pools,
             * it will reduce the cost of system.
             *  默认的pool size是1。设置这一数值不一定能提高性能,请依据你的项目的测试结果为准。初步的测试表明只有在大并发下才有提升。
             *  设置连接池的一个不良后果就是,同一个memcached的连接之间的数据更新并非同步的
             *  因此你的应用需要自己保证数据更新的原子性(采用CAS或者数据之间毫无关联)。
             */
                builder.setConnectionPoolSize(10);
		try {
			memcachedClient = builder.build();
		} catch (IOException e) {
			e.printStackTrace();
		}
		memcachedClient.setOptimizeGet(false);
		memcachedClient.setConnectTimeout(60000);
	}
	
	@Test
	public void testPutValue() throws TimeoutException, InterruptedException, MemcachedException{
			boolean flag = memcachedClient.set(ketrelQueueName, 0, "1:111");
			System.out.println(flag);
	}
	
	
	@Test
	public void testGetValue() throws TimeoutException, InterruptedException, MemcachedException{
			Object str =  memcachedClient.get(ketrelQueueName);
			System.out.println(str);
	}
	
	


}

 

 

另附kestrel官方介绍如下:

kestrel的项目主页   http://github.com/robey/kestrel
Kestrel的安装配置   http://robey.github.io/kestrel/readme.html
                    https://github.com/robey/kestrel/blob/master/docs/guide.md
                    http://dmouse.iteye.com/blog/1746171
kestrel的wiki页     http://wiki.github.com/robey/kestrel
memcache官网        http://www.memcached.org/
xmemcached项目主页  http://code.google.com/p/xmemcached/

--------------------有关kestrel定义,官方如下很多描述
Kestrel
Kestrel is a simple, distributed message queue written on the JVM, based on Blaine Cook's "starling".
Each server handles a set of reliable, ordered message queues, with no cross communication, resulting in a cluster of k-ordered ("loosely ordered") queues. Kestrel is fast, small, and reliable.

Kestrel is:
1)fast
It runs on the JVM so it can take advantage of the hard work people have put into java performance.

2)small
Currently about 2500 lines of scala, because it relies on Netty (a rough equivalent of Danger's ziggurat or Ruby's EventMachine) -- and because Scala is extremely expressive.

3)durable
Queues are stored in memory for speed, but logged into a journal on disk so that servers can be shutdown or moved without losing any data.

4)reliable
A client can ask to "tentatively" fetch an item from a queue, and if that client disconnects from kestrel before confirming ownership of the item, the item is handed to another client. In this way, crashing clients don't cause lost messages.


Kestrel is based on Blaine Cook's "starling" simple, distributed message queue, with added features and bulletproofing, as well as the scalability offered by actors and the JVM.

Each server handles a set of reliable, ordered message queues. When you put a cluster of these servers together, with no cross communication, and pick a server at random whenever you do a set or get, you end up with a reliable, loosely ordered message queue.

In many situations, loose ordering is sufficient. Dropping the requirement on cross communication makes it horizontally scale to infinity and beyond: no multicast, no clustering, no "elections", no coordination at all. No talking! Shhh!

Kestrel is a very simple message queue that runs on the JVM. It supports multiple protocols:
memcache: the memcache protocol, with some extensions
thrift: Apache Thrift-based RPC
text: a simple text-based protocol


Features
memcache protocol
thrift protocol
journaled (durable) queues
fanout queues (one writer, many readers)
item expiration
transactional reads
----------------------------有关kestrel定义,官方如上很多描述

telnet 202.108.1.121 22133
命令:
stats

Server stats
Global stats reported by kestrel are:
执行完stats命令,命令行上最上面的是返回值如下:

uptime - seconds the server has been online   kestrel服务已经启动多少秒
time - current time in unix epoch     当前kestrel服务器的时间
version - version string, like "1.2"   kestrel的版本号
curr_items - total of items waiting in all queues  所有队列的ITEM条目数的总和
total_itmes - total of items that have ever been added in this server's lifetime  曾经被添加到队列的所有条目的生存时间总和
bytes - total byte size of items waiting in all queues  被写入队列的所有条目的字节数总和
curr_connections - current open connections from clients  当前客户端打开有多少个连接
total_connections - total connections that have been opened in this server's lifetime  在服务器打开的这段时间类总共的连接数
cmd_get - total GET requests    get请求的总次数
cmd_set - total SET requests    set请求的总次数
cmd_peek - total GET/peek requests peek请求总次数
get_hits - total GET requests that received an item  get请求命令次数
get_misses - total GET requests on an empty queue  get请求无效的次数,也就是请求在了空的队列上
bytes_read - total bytes read from clients    客户端总共读取字节总数
bytes_written - total bytes written to clients  写往客户端的总字节数
queue_creates - total number of queues created  当前kestrel上已经创建的队列总数
queue_deletes - total number of queues deleted (includes expires) 已经删除的队列总数
queue_expires - total number of queues expires  已经过期的队列总数

------例如:
STAT uptime 26327844
STAT time 1375153623
STAT version 2.1.3
STAT curr_items 7727349
STAT total_items 460922839
STAT bytes 2552974113
STAT curr_connections 146
STAT total_connections 25500291
STAT cmd_get 10776718344
STAT cmd_set 460922839
STAT cmd_peek 0
STAT get_hits 383861308
STAT get_misses 10392857037
STAT bytes_read 1957725152259
STAT bytes_written 1777370590356 
------

紧接着上面那几条返回值,是许多类似下面的条目:
For each queue, the following stats are also reported:

items - items waiting in this queue    队列中当前存在的条目数
bytes - total byte size of items waiting in this queue   队列中当前条目的总字节数
total_items - total items that have been added to this queue in this server's lifetime  总共向队列中添加的条目总个数
logsize - byte size of the queue's journal file   当前队列日志的大小
expired_items - total items that have been expired from this queue in this server's lifetime 当前队列失效的条目总数
mem_items - items in this queue that are currently in memory    当前队列中存在于内存中的条目数
mem_bytes - total byte size of items in this queue that are currently in memory (will always be less than or equal to max_memory_size config for the queue)
age - time, in milliseconds, that the last item to be fetched from this queue had been waiting; that is, the time between SET and GET; if the queue is empty, this will always be zero
discarded - number of items discarded because the queue was too full
waiters - number of clients waiting for an item from this queue (using GET/t)
open_transactions - items read with /open but not yet confirmed
transactions - number of transactional get requests (irrespective of whether an item was read or not)
canceled_transactions - number of transactional get requests canceled (for any reason)
total_flushes - total number of times this queue has been flushed
age_msec - age of the last item read from the queue
create_time - the time that the queue was created (in milliseconds since epoch)

-----例如:
STAT queue_hems_ds_news_items 0
STAT queue_hems_ds_news_bytes 0
STAT queue_hems_ds_news_total_items 27231842
STAT queue_hems_ds_news_logsize 15425969
STAT queue_hems_ds_news_expired_items 0
STAT queue_hems_ds_news_mem_items 0
STAT queue_hems_ds_news_mem_bytes 0
STAT queue_hems_ds_news_age 0
STAT queue_hems_ds_news_discarded 0
STAT queue_hems_ds_news_waiters 0
STAT queue_hems_ds_news_open_transactions 0


DUMP_STATS  命令会以队列分组的格式显示出来
===========================

关于三种协议:
Protocols
Kestrel supports three protocols: memcache, thrift and text. 
The Finagle project can be used to connect clients to a Kestrel server via the memcache or thrift protocols.
Finagle项目可以通过thrift协议或者memcache协议使客户端连接到kestrel服务器

Thrift
The thrift protocol is documented in the thrift IDL: kestrel.thrift
Reliable reads via the thrift protocol are specified by indicating how long the server should wait before aborting the unacknowledged read.

Memcache
kestrel遵守memcache官方标准协议,如下这个文件有描述:
The official memcache protocol is described here: protocol.txt
https://github.com/memcached/memcached/blob/master/doc/protocol.txt


Text protocol
kestrel支持受限制的,只是文本的协议。不过还是推荐你用memcache协议替代文本协议。因为文本协议不支持可靠的读操作。
Kestrel supports a limited, text-only protocol. You are encouraged to use the memcache protocol instead.
The text protocol does not support reliable reads.





kestrel实现memcache协议的命令如下:
The kestrel implementation of the memcache protocol commands is described below.

SET <queue-name> <flags (ignored)> <expiration> <# bytes>
Add an item to a queue. It may fail if the queue has a size or item limit and it's full.

GET <queue-name>[options]
Remove an item from a queue. It will return an empty response immediately if the queue is empty. The queue name may be followed by options separated by /:

/t=<milliseconds>
Wait up to a given time limit for a new item to arrive. If an item arrives on the queue within this timeout, it's returned as normal. Otherwise, after that timeout, an empty response is returned.

/open
Tentatively remove an item from the queue. The item is returned as usual but is also set aside in case the client disappears before sending a "close" request. (See "Reliable Reads" below.)

/close
Close any existing open read. (See "Reliable Reads" below.)

/abort
Cancel any existing open read, returing that item to the head of the queue. It will be the next item fetched. (See "Reliable Reads" below.)

/peek
Return the first available item from the queue, if there is one, but don't remove it. You can't combine this with any of the reliable read options.

For example, to open a new read, waiting up to 500msec for an item:
	GET work/t=500/open
Or to close an existing read and open a new one:
	GET work/close/open

DELETE <queue-name>   删除某个队列同时删除所有条目,也会删除有关联的日志文件
Drop a queue, discarding any items in it, and deleting any associated journal files.

FLUSH <queue-name>   删除某个队列中的所有条目
Discard all items remaining in this queue. The queue remains live and new items can be added. The time it takes to flush will be linear to the current queue size, and any other activity on this queue will block while it's being flushed.

FLUSH_ALL  删除所有队列中的所有条目,就好像是每个队列都接受到了FLUSH命令一样
Discard all items remaining in all queues. The queues are flushed one at a time, as if kestrel received a FLUSH command for each queue.

VERSION   查询KESTREL的版本号
Display the kestrel version in a way compatible with memcache.

SHUTDOWN  关闭KESTREL服务器然后退出
Cleanly shutdown the server and exit.

RELOAD   重新加载配置文件
Reload the config file and reconfigure all queues. This should have no noticable effect on the server's responsiveness.

STATS  跟MEMCACHE显示的格式一样显示
Display server stats in memcache style. They're described below.

DUMP_STATS  按照队列名分组来显示
Display server stats in a more readable style, grouped by queue. They're described below.

MONITOR <queue-name> <seconds> [max-items]
Monitor a queue for a time, fetching any new items that arrive, up to an optional maximum number of items. Clients are queued in a fair fashion, per-item, so many clients may monitor a queue at once. After the given timeout, a separate END response will signal the end of the monitor period. Any fetched items are open transactions (see "Reliable Reads" below), and should be closed with CONFIRM.

CONFIRM <queue-name> <count>
Confirm receipt of count items from a queue. Usually this is the response to a MONITOR command, to confirm the items that arrived during the monitor period.

STATUS
Displays the kestrel server's current status (see section on Server Status, below).

STATUS <new-status>
Switches the kestrel server's current status to the given status (see section on Server Status, below).

------------------
另附其他参考:http://www.blogjava.net/killme2008/archive/2009/09/15/295119.html

 

分享到:
评论

相关推荐

    在.NET 6.0上使用Kestrel配置和自定义HTTPS.doc

    1. 配置 Kestrel,我们可以在 CreateHostBuilder 方法中使用 UseKestrel 方法来配置 Kestrel。 2. 在 .NET Core 6.0 中,我们可以使用 var builder = WebApplication.CreateBuilder(args); builder.WebHost....

    Kestrel持久化队列服务器

    **Kestrel持久化队列服务器详解** Kestrel是一款高性能、轻量级的消息队列系统,最初由Twitter开发并开源。它主要被设计用来处理实时流数据,提供了一个简单的基于HTTP的API来发送和接收消息。Kestrel的一个关键...

    ASP.NET Core Kestrel 中使用 HTTPS (SSL)

    在ASP.NET Core中,如果在Kestrel中想使用HTTPS对站点进行加密传输,可以按照如下方式  申请证书  这一步就不详细说了,有免费的和收费的,申请完成之后会给你一个*.pfx结尾的文件。  添加NuGet包  nuget中...

    征服 Kestrel

    2. 事件循环:Kestrel使用了Epoll或Kqueue(取决于操作系统)这样的事件通知机制,通过轮询检查套接字状态来处理新连接和数据。 3. 连接管理:Kestrel维护了一个连接池,根据预设的策略管理短连接和长连接,有效地...

    征服 Kestrel + XMemcached

    Kestrel是一个高性能、异步的分布式消息队列,而XMemcached则是一个广泛使用的Java客户端,用于连接到Memcached缓存服务器。在这里,我们将会探讨这两个技术的基本概念、它们在IT领域的应用以及如何将它们结合使用。...

    Kestrel框架的使用demo

    1. **轻量级与高效**:Kestrel使用现代HTTP/2协议,并且支持HTTP/1.1,提供了高效的网络I/O处理,确保应用程序的响应速度。 2. **跨平台兼容**:Kestrel是.NET Core的一部分,因此它可以无缝运行在所有.NET Core...

    征服 Kestrel + XMemcached + Spring TaskExecutor

    通过深入学习Kestrel的配置、管理和监控,掌握XMemcached的使用技巧,以及理解Spring TaskExecutor的线程池管理策略,开发者可以有效地优化应用程序的性能,同时保证系统的可伸缩性和可靠性。在实际项目中,可能还...

    一个超级简单方便的网关,基于Kestrel+Yarp实现的网关 支持动态配置路由,支持动态配置集群,支持动态配置HTTPS证书

    它利用了.NET Core中的Kestrel服务器以及YARP(Yet Another Reverse Proxy)库,使得在不重启服务的情况下,就能实现各种网络配置的实时更新,极大地提高了运维效率。 **Kestrel:高性能Web服务器** Kestrel是.NET...

    ASP.NET Core 因为 Nginx 配置 Connection 为 Upgrade 导致 Kestrel 返回 400

    在某些情况下,当 Nginx 配置不当,尤其是 `Connection` 字段设置为 `Upgrade` 时,可能会导致 Kestrel(ASP.NET Core 的内置 web 服务器)返回 400 错误。这个问题通常与 WebSocket 协议升级有关。 WebSocket 是一...

    ASP.net示例代码

    这些示例代码可能包含了如何创建、配置和操作Web Forms的实例,例如使用Button、TextBox、Label等控件,以及处理Page生命周期事件,如Load、Click等。 另外,ASP.NET MVC(Model-View-Controller)是一个轻量级的、...

    kestrel-task-executor:Kestrel + XMemcached + Spring TaskExecutor

    这个项目名为"kestrel-task-executor",它结合了Kestrel消息队列、XMemcached缓存客户端以及Spring的TaskExecutor框架,构建了一个强大的任务处理平台。以下将详细解析这个项目的组成部分和它们如何协同工作。 1. *...

    .NET Core WebSocket示例

    9. **部署和运行**:完成开发后,可以使用`dotnet publish`命令打包应用,然后在目标环境中(如IIS、Kestrel等)运行。配置文件(如appsettings.json)可以用来控制服务器设置。 10. **调试和测试**:利用Visual ...

    Python库 | kestrel-lang-1.0.5.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:kestrel-lang-1.0.5.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Kestrel封装成WindowServer.zip

    在一些开发过程中,会在局域网内搭建webapi服务作为移动端的服务接口使用,但是每次实施人员要到客户现场安装iis等工具,还有一些web的配置,非常繁琐,所以想着把webapi封装到WindowService中,可以通过自定义的...

    asp.net core中灵活的配置方式详解

    这个命令会告诉Kestrel Web服务器监听所有可用的网络接口地址,端口为5000。这种方式十分适合开发阶段的快速测试。 不过,当你需要运行已发布的程序时,命令就有所不同。此时,你应使用如下命令: ```shell dotnet...

    .NET-KestrelHttpServer一个用于ASPNETCore的跨平台Web服务器

    本文将深入探讨Kestrel的相关知识点,包括其工作原理、主要特性和使用场景。 ### 工作原理 Kestrel基于Libuv库,这是一个跨平台的异步I/O库,广泛应用于Node.js等项目。Kestrel利用Libuv处理网络连接,确保在高...

    Python库 | kestrel_lang-1.1.0-py3-none-any.whl

    安装完成后,你就可以在你的Python代码中导入并使用`kestrel_lang`库了,例如: ```python import kestrel_lang # 接下来,你可以调用库提供的函数或类,具体取决于库的功能 result = kestrel_lang.some_function...

    web服务器KestrelHttpServer.zip

    4. **可配置性**:Kestrel提供丰富的配置选项,允许开发者根据需求调整服务器的行为,例如设置监听端口、限制连接数等。 5. **可扩展性**:Kestrel设计为模块化,可以通过中间件系统轻松扩展其功能。 6. **集成...

    message_system_test_report.rar_ActiveMQ java_activemq_httpsqs_me

    Kestrel使用内存存储,因此具有较高的性能,但数据持久化可能不如其他队列强大。部署Kestrel时,需要安装其依赖库并配置服务器端口和数据存储路径。性能测试时,主要考察其处理速度、内存占用和故障恢复能力。 ...

Global site tag (gtag.js) - Google Analytics