iOS RabbitMQ了解(一)

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

github上的说明如下:

使用CocoaPods进行安装

  1. 将以下内容添加到您的Podfile中:

    pod 'RMQClient', '~> 0.11.0'
    
    

    我们建议添加use_frameworks!以启用模块化导入(仅Objective-C)。

  2. 运行pod install

  3. 使用打开项目open MyProject.xcworkspace

Objective-C用户:使用导入@import RMQClient;当前会在Xcode中产生错误(无法构建模块'RMQClient'),但这不会阻止代码的编译和运行。使用鳄鱼进口可以避免以下Xcode错误:#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

文献资料

(基本)用法示例

  1. 实例化一个RMQConnection

    让委托=  RMQConnectionDelegateLogger()//实现RMQConnectionDelegate自己对错误做出反应
    let conn =  RMQConnection(uri:“ amqp:// guest:guest @ localhost:5672 ”,委托:委托)
    
  2. 连接:

    康恩 开始()
    
  3. 创建一个频道:

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

    让q = ch。排队(“ myqueue ”)
    q。订阅({M在
       印刷(“收到的:\(字符串(数据:M体,编码:字符串。编码。UTF8)) ”)
    })
    Q值。发布(“富”。数据(使用:字符串。编码。utf8))
    
  5. 完成后关闭连接:

    conn.close()
    
    

有关更多详细说明,请参见教程

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.

注:以上为网址上摘抄

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容