我在application.conf
中有以下配置:
bounded-mailbox {
mailbox-type = "akka.dispatch.BoundedMailbox"
mailbox-capacity = 100
mailbox-push-timeout-time = 3s
}
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = INFO
daemonic = on
}
这是我配置演员的方式
public class MyTestActor extends UntypedActor implements RequiresMessageQueue<BoundedMessageQueueSemantics>{
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof String){
Thread.sleep(500);
System.out.println("message = " + message);
}
else {
System.out.println("Unknown Message " );
}
}
}
现在我来初始化这个演员:
myTestActor = myActorSystem.actorOf(Props.create(MyTestActor.class).withMailbox("bounded-mailbox"), "simple-actor");
在这之后,在我的代码中,我向这个actor发送了3000条消息。
for (int i =0;i<3000;i++){
myTestActor.tell(guestName, null);}
我希望看到的是我的队列已满,但我的消息每半秒钟都会在onReceive方法中打印,就像什么也没有发生一样。因此,我认为我的邮箱配置未应用。
我做错了什么?
更新:我创建了一个订阅死信事件的Actor。
deadLetterActor = myActorSystem.actorOf(Props.create(DeadLetterMonitor.class),"deadLetter-monitor");
我已经安装了用于队列监控的Kamon:
向actor发送3000条消息后,Kamin显示如下内容:
Actor: user/simple-actor
MailBox size:
Min: 100
Avg.: 100.0
Max: 101
Actor: system/deadLetterListener
MailBox size:
Min: 0
Avg.: 0.0
Max: 0
Actor: system/deadLetter-monitor
MailBox size:
Min: 0
Avg.: 0.0
Max: 0
mailbox-push-timeout-time
非零值 - 请查看我的更新答案。 - Andriy Plokhotnyuk