ios - Cloud AMPQ 与 iOS APP 集成

标签 ios swift rabbitmq

我正在努力将云 AMPQ 集成到我的 iOS 应用程序中。使用 RabbitMQ 客户端,无法与服务器成功通信。

我检查了下面的堆栈溢出链接以与服务器进行通信: stack overflow link

上面链接中共享的示例源已损坏。请建议我可能的解决方案。提前致谢

最佳答案

您应该使用官方客户端库:https://github.com/rabbitmq/rabbitmq-objc-client (Swift + ObjC 兼容)

基本用法(摘自 repo):

  1. 实例化一个 RMQConnection:

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

    conn.start()
    
  3. 创建 channel :

    let ch = conn.createChannel()
    
  4. 使用 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. 完成后关闭连接:

    conn.close()
    

根据提供商的不同,您需要手动构建连接 URI。例如 Heroku 已经在它的仪表板中展示了它。这是有关受支持参数的文档:https://www.rabbitmq.com/uri-spec.htmlhttps://www.rabbitmq.com/uri-query-parameters.html

Heroku 上的示例 URI:

amqp://xxxxxxx:yyy-zzz@aaaaaa.bigwig.lshift.net:10674/bbbbbbb

格式:

amqp_URI = "amqp://" [ username [ ":" password ] "@" ] host [ ":" port ] [ "/" vhost ] [ "?" query ]

关于ios - Cloud AMPQ 与 iOS APP 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45916220/

相关文章:

iOS( swift ): UITextField is **not** first responder after becomeFirstResponder method is called?

python - MySQL 触发器到 RabbitMQ

带有 spring amqp 的 rabbitmq - 出现 AmqpException 时消息卡住

ios - @interface 和@implementation 指令中括号内的文本是什么意思?

iphone - iOS:已授予权限?

ios - WKInerfaceLabel 放置在 WKInerfaceTable 之上,但不希望它与 WKInterfaceTable 一起滚动

swift - 小费计算器 - Swift

swift - 使用属性作为同一类中方法的默认参数值

python - celery 任务消失

ios - 如何获取 .mobileprovision 以在 Windows 上构建 phonegap iphone 应用程序?