0%

阅读全文 »

https://cloud.tencent.com/developer/article/2113802

什么是消息队列

消息队列是在消息传输过程中保存消息的容器。 通常有生产者和消费者两个角色:

  • 生产者只负责发送数据到消息队列,谁消费他不管
  • 消费者只负责从消息队列中取数据处理,谁发送数据他不管

常见消息队列中间件

  • Kafka 高吞吐量实时日志采集
  • RabbitMQ Erlang语言, 灵活性和易用性,中小规模应用
  • RocketMQ 阿里出品, Java开发, 国内市场有很高知名度和应用案例

为什么使用消息队列

阅读全文 »

前言

Linux安装RabbitMQ
官方教程

1. Hello RabbitMQ

使用Python pika客户端, 写一个简单的生产者和消费者

1
Producer ------> Queue -----> Consumer

编写Producer(send.py)

先连接Broker, 建立connection和channel

1
2
3
4
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()

接着声明一个队列; 在RabbitMQ中,消息不是直接发送到队列,而是先发送到交换机(exchange), 由交换机发送到队列。

1
channel.queue_declare(queue='hello')

使用basic_publish发送消息。 这里使用默认交换机(‘’), routing_key参数指定为队列名称

1
channel.basic_publish(exchange='', routing_key='hello', body='Hello World!')
阅读全文 »

Overview

1
2
3
4
5
6
7
frontend ------->  backend ---------> MQ ----------->  VA(On-premise)
/|\ |
|------------------------------|

peter.backend.com:443 backend
peter.channel.com:5672 MQ
peter.frontend.com frontend

Design

Auto-upgrade

dispatchAutoUpgradeInOneHourForAll

  • find all running appliances, group by customer_id
  • check if appliance need upgrade
    • check schedule update time is within next 1 hour.
    • check target version valid (expectedStatus = RUNNING and status is not RUNNING)
    • don’t upgrade rollback appliances.
    • don’t upgrade all appliances at the same time. upgrade half appliances first.
  • trigger appliance upgrade
    • get firmware download link
    • update db, add dbentry for IotTask, update appliance status(upgrading, upgradetaskId: taskId)
    • publish iot Task
  • receive response from Appliance
    • write task to db

阅读全文 »