在微服务架构中,消息队列带来哪些好处呢
1. 改善写操作请求的响应时间:生产者写给队列即可返回,无需等待下游服务响应,缩短链路调用时间
2. 更容易进行伸缩:小功能解偶为独立服务,更容易伸缩,提升处理能力
3. 削峰填谷:控制消费速度,降低系统访问高峰压力
4. 隔离失败:消费者处理消息失败,不会传递给生产者
5. 降低耦合:上下游服务解藕
6. 保证最终一致性
多个消息生产者向消息队列发送消息,多个消费者消费消息,每个消息只会被一个消费者消费
多个消息消费者可以订阅同一个主题,每个消费者都可以收到这个主题的消息拷贝,然后按照自己的业务逻辑分别进行处理计算
Apache ActiveMQ® is the most popular open source, multi-protocol, Java-based message broker.
Apache RocketMQ™ is a unified messaging engine, lightweight data processing platform.
RabbitMQ is lightweight and easy to deploy on premises and in the cloud. It supports multiple messaging protocols. RabbitMQ can be deployed in distributed and federated configurations to meet high-scale, high-availability requirements.
Apache Kafka is an open-source distributed event streaming platform used by thousands of companies for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.
网上常见的对比:
从不同使用场景对比下Kafka、 RabbitMQ
设置 acks=all,一定不会丢。
要求是, leader 接收到消息,所有的 follower 都同步到了消息之后,才认为本次写成功了。
如果没成功,生产者会自动不断的重试,重试无限次。容易导致重复消费。
设置四个参数
关闭自动offset,启用手动offset
持久化设置
关闭自动ack,启用手动ack
Kafka消息重复场景:消费完成,在准备提交offset时,还没提交,消费者重启
基本措施:
1.rabbitmq支持PUSH、PULL
RabbitMQ is the most widely deployed open source message broker.
More than 80% of all Fortune 100 companies trust, and use Kafka.
Flexible & Powerful Open Source Multi-Protocol Messaging
Apache RocketMQ™ is a unified messaging engine, lightweight data processing platform.