Hi everyone,
Our messages are long processing messages and we want to be able to track where the message is spending time in. As such, we want to be able to log how long a message is in the queue also. Is there way to do it? Currently, I am tracking the queue size with this wrapping class. The message object I am sending has a transaction id. One way I was thinking is that perhaps I can log the message’s transaction id as I enqueue and dequeue. However, the parameter of the enqueue is an Envelope, not my object. Could you advise?
Thanks in advance for your suggestion,
Grace
class LoggingMailbox(owner: ActorRef, system: ActorSystem, sizeLimit: Int)
extends UnboundedMailbox.MessageQueue {private lazy val log = Logging(system, classOf[LoggingMailbox])
private val path = owner.path.toString
private val queueSize = new AtomicInteger
private val dequeueOperation = “dequeue”
private val enqueueOperation = “enqueue”override def dequeue(): Envelope = {
val x = super.dequeue()
if (x ne null) {
val size = queueSize.decrementAndGet()
logSize(size, dequeueOperation)
}
x
}override def enqueue(receiver: ActorRef, handle: Envelope): Unit = {
super.enqueue(receiver, handle)
val size = queueSize.incrementAndGet()
logSize(size, enqueueOperation)
}
…
}