Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

메시지는 전송시 유니크한 배달ID가 발생하며, 최송 수신처 에게 확인을통해

실패한 메시지에대해 재전송을 할수가 있습니다. 이러한 과정없이 네트워크 에러를 감지하여

실패시 재전송을 하려는 전략은 실패할 가능성이 높습니다.

어디서 유실되었는지 파악하는것이 더 어렵기 때문입니다.

...



AtLeastOnceDelivery 액터 설계

송신자 설계

Code Block
languagejava
themeEmacs
class MyPersistentActor extends AbstractPersistentActorWithAtLeastOnceDelivery {
  private final ActorSelection destination;

  public MyPersistentActor(ActorSelection destination) {
      this.destination = destination;
  }

  @Override public String persistenceId() {
    return "persistence-id";
  }

  @Override
  public Receive createReceive() {
    return receiveBuilder().
      match(String.class, s -> {
        persist(new MsgSent(s), evt -> updateState(evt));
      }).
      match(Confirm.class, confirm -> {
        persist(new MsgConfirmed(confirm.deliveryId), evt -> updateState(evt));
      }).
      build();
  }

  @Override
  public Receive createReceiveRecover() {
    return receiveBuilder().
        match(Object.class, evt -> updateState(evt)).build();
  }

  void updateState(Object event) {
    if (event instanceof MsgSent) {
      final MsgSent evt = (MsgSent) event;
      deliver(destination, deliveryId -> new Msg(deliveryId, evt.s));
    } else if (event instanceof MsgConfirmed) {
      final MsgConfirmed evt = (MsgConfirmed) event;
      confirmDelivery(evt.deliveryId);
    }
  }
}


수신자 설계

Code Block
languagejava
themeEmacs
class MyDestination extends AbstractActor {
  @Override
  public Receive createReceive() {
    return receiveBuilder()
      .match(Msg.class, msg -> {
        // ...
        getSender().tell(new Confirm(msg.deliveryId), getSelf());
      })
      .build();
  }
}

...