iOS RabbitMQ了解(一)

github:https://github.com/rabbitmq/rabbitmq-objc-client

github上的說(shuō)明如下:

使用CocoaPods進(jìn)行安裝

  1. 將以下內(nèi)容添加到您的Podfile中:

    pod 'RMQClient', '~> 0.11.0'
    
    

    我們建議添加use_frameworks!以啟用模塊化導(dǎo)入(僅Objective-C)。

  2. 運(yùn)行pod install。

  3. 使用打開(kāi)項(xiàng)目open MyProject.xcworkspace。

Objective-C用戶:使用導(dǎo)入@import RMQClient;當(dāng)前會(huì)在Xcode中產(chǎn)生錯(cuò)誤(無(wú)法構(gòu)建模塊'RMQClient'),但這不會(huì)阻止代碼的編譯和運(yùn)行。使用鱷魚(yú)進(jìn)口可以避免以下Xcode錯(cuò)誤:#import <RMQClient/RMQClient.h>。(Objective-C users: importing with @import RMQClient; currently produces an error in Xcode (Could not build module 'RMQClient'), but this should not prevent code from compiling and running. Using crocodile imports avoids this Xcode bug: #import <RMQClient/RMQClient.h>.)

支持的功能

Supported Features

文獻(xiàn)資料

(基本)用法示例

  1. 實(shí)例化一個(gè)RMQConnection

    讓委托=  RMQConnectionDelegateLogger()//實(shí)現(xiàn)RMQConnectionDelegate自己對(duì)錯(cuò)誤做出反應(yīng)
    let conn =  RMQConnection(uri:“ amqp:// guest:guest @ localhost:5672 ”,委托:委托)
    
  2. 連接:

    康恩 開(kāi)始()
    
  3. 創(chuàng)建一個(gè)頻道:

    令ch = conn。createChannel()
    
  4. 使用頻道:

    讓q = ch。排隊(duì)(“ myqueue ”)
    q。訂閱({M在
       印刷(“收到的:\(字符串(數(shù)據(jù):M體,編碼:字符串。編碼。UTF8)) ”)
    })
    Q值。發(fā)布(“富”。數(shù)據(jù)(使用:字符串。編碼。utf8))
    
  5. 完成后關(guān)閉連接:

    conn.close()
    
    

有關(guān)更多詳細(xì)說(shuō)明,請(qǐng)參見(jiàn)教程。

Documentation

(Basic) Usage Example

  1. Instantiate an RMQConnection:

    let delegate = RMQConnectionDelegateLogger() // implement RMQConnectionDelegate yourself to react to errors
    let conn = RMQConnection(uri: "amqp://guest:guest@localhost:5672", delegate: delegate)
    
  2. Connect:

    conn.start()
    
  3. Create a channel:

    let ch = conn.createChannel()
    
  4. Use the channel:

    let q = ch.queue("myqueue")
    q.subscribe({ m in
       print("Received: \(String(data: m.body, encoding: String.Encoding.utf8))")
    })
    q.publish("foo".data(using: String.Encoding.utf8))
    
  5. Close the connection when done:

    conn.close()
    
    

See the tutorials for more detailed instructions.

注:以上為網(wǎng)址上摘抄

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請(qǐng)通過(guò)簡(jiǎn)信或評(píng)論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容