Reputation: 99
I'm trying to use op-rabbit https://github.com/SpinGo/op-rabbit to connect my Scala App to RabbitMq. The example code https://github.com/SpinGo/op-rabbit/blob/master/demo/src/main/scala/demo/Main.scala works perfectly fine.
I want to work on it with the Intellij-idea. The IDE makes problems on the consume code:
channel(qos=3) {
consume(demoQueue) {
body(as[Data]) { data =>
println(s"received ${data}")
ack
}
}
}
I get an error on data => ... it says its a type mismatch
Type mismatch, expected: ::[Data, HNil] => op_rabbit.Handler, actual: Data => op_rabbit.Handler
I would be absolutly fine with annotating the data variable manually if this solves the problem i tried to annotated data as HList from shapeless.
channel(qos=3) {
consume(demoQueue) {
body(as[Data]) { data: HList =>
println(s"received ${data}")
ack
}
}
}
The IDE was happy with it... unlucky the compiler not really :D :( . Like this the code doesnt compile anymore.
Any idea?
Intellij and the Scala Plugin are updated to the newest version.
Upvotes: 3
Views: 150
Reputation: 51703
Well, it's better if IDE complains and not compiler does.
Type of data
is Data
and not HList
or Data :: HNil
channel(qos=3) {
consume(demoQueue) {
body(as[Data]) { (data: Data) =>
println(s"received ${data}")
ack
}
}
}
You should get used that IDE highlights code in Scala sometimes incorrectly. Path-dependent types, implicits, macros etc. are sometimes too complicated for IDE to handle.
The following code is highlighted correctly in 2017.3 EAP (Ultimate Edition) Build #IU-173.3302.5
val directive = body(as[Data])
channel(qos = 3)(
consume(demoQueue)(
directive(data => {
println(s"received ${data}")
ack
})
)
)
Upvotes: 3
Reputation: 99
As a short term solution i took this way:
val handle = (data: Data) => {
println(s"received ${data}")
ack
}
val demoQueue = Queue("demo", durable = false, autoDelete = true)
val subscription = Subscription.run(rabbitControl) {
channel(qos=3) {
consume(demoQueue) /*_*/ {
body(as[Data]) {handle}
}
}
}
I disabled the type check on the problematic block. Nevertheless i want to have type checking in my handling code. I moved that part out to the handle function. This way the IDE checks the handle function. With /* _ */ you can disable type checking on a specific part of the code.
Still hope for better solutions.
Upvotes: 1