In my model there are about 8-9 Scala Actors. Each actor has its own queue on RabbitMQ Server
in act method of each Actor .It is continuously listing to the queue like
def act {
this ! 1
loop {
react {
case 1 => processMessage(QManager.getMessage); this ! 1
}
}
}
I a rabbitMq QManager getMessage Method
def getMessage: MyObject = {
getConnection
val durable = true
channel.exchangeDeclare(EXCHANGE, "direct", durable)
channel.queueDeclare(QUEUE, durable, false, false, null)
channel queueBind (QUEUE, EXCHANGE, _ROUTING_KEY)
consumer = new QueueingConsumer(channel)
channel basicConsume (QUEUE, false, consumer)
var obj = new MyObject
try {
val delivery = consumer.nextDelivery
val msg = new java.io.ObjectInputStream(
new java.io.ByteArrayInputStream(delivery.getBody)).readObject()
obj = msg.asInstanceOf[MyObject]
channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false)
} catch {
case e: Exception =>logger.error("error in Get Message", e);endConnection
}
endConnection
obj
}
All 9 Actors has its own object type and a own QManager
in a GetMessage I am using Rabbitmq QueueConsumer
val delivery = consumer.nextDelivery
and the nextDelivery method returns a object when itfounds in a queue this method puts actor in waiting state
when i start all 8 actors only 4 of them works fine other are not stated. I have test each and every actor running interdependently they works fine when started Alone
The problem occurs when i start more that 4 actors
is therer any Problem with threading of scala actors.