<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ### MQ 簡單隊列實戰 * [ ] 模型: ![](https://box.kancloud.cn/2e643cdc25dba4c04590066c9e2656d4_483x108.png) >[danger] P 是我們的生產者 > 中間的框是一個隊列,代表消費者保留的消息緩沖區。 > C 是我們的消費者 ***** 代碼演示: ``` 'use strict'; const Controller = require('egg').Controller; /** * 一對一隊列演示 */ // 頻道名稱 const queueName = 'hasone' class UserController extends Controller { // 生成者 async send() { // 1. 獲取要發送的消息 const { msg } = this.ctx.query // 2. 創建頻道 const ch = await this.app.amqplib.createChannel(); // 3. 創建隊列 durable 關閉持久化存儲 await ch.assertQueue(queueName, { durable: false } ); // 4. 發送消息 const ok = await ch.sendToQueue(queueName, Buffer.from(msg)); // 5. 關閉連接 await ch.close(); this.ctx.body = ok; this.ctx.status = 200; } // 消費者 async work() { // 1. 創建頻道 const ch = await this.app.amqplib.createChannel(); // 2. 選擇隊列 await ch.assertQueue(queueName, { durable: false }); //3. 接收隊列的消息 const resultMsg = await new Promise(resolve => ch.consume(queueName, msg => resolve(msg), { noAck: true })); // 4. 顯示消息內容 if (resultMsg !== null) { ch.ack(resultMsg); await ch.close(); const { content } = resultMsg; this.status = 200; this.ctx.body = { msg: content.toString() } } else { this.ctx.body = '隊列消費失敗' this.ctx.status = 500; } } } module.exports = UserController; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看