ios - 无法使用 Swift 连接 RabbitMQ

标签 ios swift sockets rabbitmq

我开始将 RabbitMQ 与 Swift 结合使用。我按照 github 上的 RabbitMQ 库中的示例代码进行操作:

let delegate = RMQConnectionDelegateLogger() 
let conn = RMQConnection(uri: "amqp://localhost:5672", delegate: delegate)

conn.start()

let ch = conn.createChannel()

let q = ch.queue("hello")
q.subscribe { rm in
    print(rm.content )
}

我多次遇到这些错误:

Will start recovery for connection: <' Received connection: <'RMQConnection: 0x7fdb43c73670> disconnectedWithError: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}RMQConnection: 0x7fdb43c73670>

在 RabbitMQ 日志上我收到此错误:

Error on AMQP connection <0.271.0> (172.19.0.1:53144 -> 172.19.0.4:5672, state: starting): PLAIN login refused: user '' - invalid credentials

我可以在哪里定义凭据?我搜索了很多例子但找不到任何东西。

最佳答案

检查一下:

Can't access RabbitMQ web management interface after fresh install

然后将 URL 连接更改为:

'amqp://test:test@localhost:5672/'

关于ios - 无法使用 Swift 连接 RabbitMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38538340/

相关文章:

java - 无法在方法中使用 getOutputStream 和 getInputStream

objective-c - 写入文档目录中的plist时出错

objective-c - Nib 中的 2 个表格 View

ios - 在 Swift 中查找类的兄弟 View

ios - inputAccessoryView 的 autoResizingMask 不起作用

ios - 能否将本 map 片设置为SDWebImage的离线图片?

ios - 如何使用标签文本 (Int) 值编写 if 条件

ios - 核心数据轻量级迁移而不会在启动时被杀死

.net - 如何将 SimplSockets 与 "hello world"项目的委托(delegate)一起使用?

java - ObjectOutputStream 对象有时会自动刷新。我如何才能准确地知道何时依赖此行为以及何时手动刷新?