私はAkka Distributed Pub/Subを使用しており、出版社とサブスクライバは1つです。私の出版社は加入者よりもずっと高速です。ある時点後に出版社を遅らせる方法はありますか?Akka Distributed Pub/Subバックプレッシャー
出版社コード:
public class Publisher extends AbstractActor {
private ActorRef mediator;
static public Props props() {
return Props.create(Publisher.class,() -> new Publisher());
}
public Publisher() {
this.mediator = DistributedPubSub.get(getContext().system()).mediator();
this.self().tell(0, ActorRef.noSender());
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Integer.class, msg -> {
// Sending message to Subscriber
mediator.tell(
new DistributedPubSubMediator.Send(
"/user/" + Subscriber.class.getName(),
msg.toString(),
false),
getSelf());
getSelf().tell(++msg, ActorRef.noSender());
})
.build();
}
}
加入者コード:残念ながら
public class Subscriber extends AbstractActor {
static public Props props() {
return Props.create(Subscriber.class,() -> new Subscriber());
}
public Subscriber() {
ActorRef mediator = DistributedPubSub.get(getContext().system()).mediator();
mediator.tell(new DistributedPubSubMediator.Put(getSelf()), getSelf());
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(String.class, msg -> {
System.out.println("Subscriber message received: " + msg);
Thread.sleep(10000);
})
.build();
}
}