rabbitMQ的Streams
2021年7月,3.9 版才加入的新功能。https://www.rabbitmq.com/changelog.html
(其实一点都不新,kafka都加入10年了吧?)
官网说明 https://www.rabbitmq.com/streams.html
几个特点(其实就是抄kafka的 stream)
1 持久化
2 append-only(不可变数据)
3 非破坏性消费者语义(non-destructive consumer semantics) 绕嘴。
使用场合:
1. 大扇出
多个消费者 消费同一个队列的消息的时候。用stream发布1次,就不用管了。反正数据在stream里持久化了
2. 重放/时间旅行
发布的时序和持久化
3.大规模日志,性能。
但是具体实现上还是区分2种stream-core和steam-plugin
具体参见 https://gist.github.com/Gsantomaggio/149b604113bf9d2e044a0f89531c101f
Core-Stream
vs Stream-Plugin
Feature | Stream-Core | Stream-Plugin |
---|---|---|
Activation | Built-in | Must be enabled |
Protocol | AMQP 0.9.1 | RabbitMQ Stream |
Client library | AMQP 0.9.1 | RabbitMQ Stream |
Port | 5672 | 5552 |
Format | consume AMQP 0.9.1/1.0 messages | consume AMQP 0.9.1/1.0 messages |
Sub-Entry batching | Not supported | Supported |
Offset tracking | Use external store | Built-in server side |
Publishing deduplication | Not supported | Supported |
Throughput | Hundreds of thousands per second | Millions messages per second |
TLS | Supported | Supported |
See here for all the clients: https://www.rabbitmq.com/devtools.html
简单说不用plugin的各种0.9.1的客户端 比如js的stompjs,python的pika,clojure的langohr, 也都是可以declare/publish/subscribe stream类型的queue的。只不过性能有损失。但是对小规模应用足够了
二 rabbitmq部署
2.1创建rabbitmq.conf
stream.advertised_host = localhost
为了publish到stream,必须声明这个,因为stream是区分leader的。
2.2dockerfile
FROM rabbitmq:3-management LABEL purpose = 'stomp for browser js/cljs' RUN rabbitmq-plugins enable rabbitmq_stream_management rabbitmq_web_stomp COPY ./rabbitmq.conf /etc/rabbitmq/rabbitmq.conf
安装插件,复制配置文件
2.3 docker-compose.yml
version: '3.8' services: rabbitmq-stream: restart: always build: ./ command: rabbitmq-server environment: RABBITMQ_ERLANG_COOKIE: SWQOKODSQALRPCLNMEQG RABBITMQ_DEFAULT_USER: guest RABBITMQ_DEFAULT_PASS: guest ports: - "15672:15672" # mangerment webpage - "5672:5672" #rabbitmq - "15674:15674" #web stomp - "61613:61613" #stomp - "5552:5552" # stream
2.4 启动
docker-compose up
三 pika (python)
—————————————