我在docker上启动了RabbitMq。这是docker ps
:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93dcba1c9b74 rabbitmq:3 "docker-entrypoint.s…" About a minute ago Up 9 seconds 4369/tcp, 5671-5672/tcp, 25672/tcp rabbitTestQueue
然后我在application.conf中使用了op-rabbit的Scala代码和以下配置:
-rabbit {
topic-exchange-name = "rabbitTestQueue"
channel-dispatcher = "op-rabbit.default-channel-dispatcher"
default-channel-dispatcher {
type = Dispatcher
executor = "fork-join-executor"
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 4
}
throughput = 100
}
connection {
virtual-host = "/"
hosts = ["rabbitTestHost"]
#username = "guest"
#password = "guest"
port = 5672
ssl = false
connection-timeout = 3s
}
}
这是我的代码:
import akka.actor.{ActorSystem, Props}
import com.spingo.op_rabbit._
import scala.concurrent.ExecutionContext
import play.api.libs.json._
case class Query(query: String)
object MainApp extends App {
import PlayJsonSupport._
implicit val actorSystem = ActorSystem("KaliumApp")
implicit val dataFormat = Json.format[Query]
val rabbitControl = actorSystem.actorOf(Props(new RabbitControl))
implicit val recoveryStrategy = RecoveryStrategy.nack(false)
import ExecutionContext.Implicits.global
val queryQueue = Queue("rabbitTestQueue", durable = false, autoDelete = true)
val subscription = Subscription.run(rabbitControl) {
import Directives._
channel(qos=3) {
consume(queryQueue) {
body(as[Query]) { queryObj =>
println(s"received ${queryObj.query}")
ack
}
}
}
}
}
当我运行我的代码时,我收到以下错误:
akka://MainApp/user/$a/connection in Disconnected received Connect: can't connect to amqp://guest@{rabbitTestHost:5672}:5672//, retrying in 10 seconds
我该如何解决这个问题?我应该更改application.conf
中的某些配置吗?
答案 0 :(得分:2)
amqp:// guest @ {rabbitTestHost:5672}:5672 //
5672在这里不是重复的,而只是op-rabbit打印连接日志的方式。
答案 1 :(得分:1)
RabbitMQ团队监控the rabbitmq-users
mailing list,有时只回答StackOverflow上的问题。
基于此消息:
Connect: can't connect to amqp://guest@{rabbitTestHost:5672}:5672//
["rabbitTestHost"]
的值rabbitTestHost:5672
似乎只有rabbitTestHost
。请注意,5672
在连接消息中重复。