zbus = mq + rpc
微服务,系统总线

了解更多 源码: Gitee

消息队列(MQ)

极速磁盘、内存队列
消息模式: 单播、广播、组播、订阅
通道优化: 进程内, IPC, TCP

远程方法调用(RPC)

支持同步、异步调用
面向接口动态代理
实时负载均衡

代理服务(Proxy)

HTTP DMZ代理
HTTP 反向代理
TCP 透明代理

轻量级

发行大小 ~3M
核心 ~400K, 极少依赖
自主掌控、二次开发

高可用

内置高可用模块
无应用故障单点
弹性增加服务器节点

高性能

磁盘队列读写,SSD 500M+/s
生产者、消费者高速并发
横向可弹性扩展

安全控制

支持SSL/TLS安全通信
基于Token的细粒度权限控制
支持DMZ网络限制

多语言支持

Java, .NET, JS
PHP, Python, C++
Go

协议简洁

类HTTP 头部扩展,基于TCP
浏览器友好,内置Websocket
容易实现新语言API

速度即是乐趣 · 简洁之美
 
    //极速启动zbus
public static void main(String[] args) throws Exception {  
    final MqServer server = new MqServer(); //所有参数使用默认,可以使用Config配置
    server.start();  
}
    
 
import io.zbus.mq.Broker;
import io.zbus.mq.Message;
import io.zbus.mq.Producer; 
//ignore class + main
Broker broker = new Broker("localhost:15555");  //可以是多地址HA
Producer p = new Producer(broker);  

p.declareTopic("MyTopic"); //当Topic不存在的时候,需要创建(可多次重复)
		 
Message msg = new Message();
msg.setTopic("MyTopic");     // [R] 消息主题必须		
msg.setBody("Hello, from Java"); //消息是透明二进制类型
		
p.publish(msg); 
		
broker.close();

 
using Zbus.Mq;
//ignore class + main
using (Broker broker = new Broker("localhost:15555")) 
{
    Producer p = new Producer(broker);
    await p.DeclareTopicAsync("MyTopic");
    Message msg = new Message
    {
        Topic = "MyTopic",
        BodyString = "Hello, from .NET",
    }; 
    await p.PublishAsync(msg); 
} 

 
var zbus = require("zbus");
Broker = zbus.Broker;
Producer = zbus.Producer; 

var broker = new Broker("localhost:15555");  
var p = new Producer(broker);

await p.declare('MyTopic');  

await p.publish({topic: 'MyTopic', body: 'Hello, from JS'}) 

broker.close();

 
from zbus import Broker, Producer, Message
broker = Broker('localhost:15555') 
p = Producer(broker)

p.declare('MyTopic') 

msg = Message()
msg.topic = 'MyTopic'
msg.body = 'Hello, from Python'

p.publish(msg)
 
broker.close()

 
$loop = new EventLoop(); 
$broker = new Broker($loop, "localhost:15555", true); // enable sync mode
$producer = new Producer($broker);

$broker->on('ready', function() use($loop, $broker, $producer){   
	$msg = new Message();
	$msg->topic = 'MyTopic';
	$msg->body = 'Hello, from PHP';
	
	$res = $producer->publish($msg);
	
	$broker->close();  
	$loop->stop(); //stop anyway
}); 

$loop->runOnce();

 
#include "Producer.h"  
using namespace zbus;
using namespace std;

int main(int argc, char* argv[]) { 
	Broker broker("localhost:15555");
	Producer p(&broker);

	p.declareTopic("MyTopic");  

	Message msg;
	msg.setTopic("MyTopic");
	msg.setBody("Hello, from C++");

	p.produce(msg);

	return 0; //broker closed implicitly by C++ destructor
}

 
URL format:
http://server/topic/?key=value

1) Declare Topic
http://localhost:15555/MyTopic?cmd=declare

2) Produce
http://localhost:15555/MyTopic?body=from_http


应用案例 · Since 2009 +