0

I have tried following code to view/capture dead letters but it is not working in a way it should. What I am missing.exactly? My aim is just to view all the dead letters that are being delivered to deadletters actor.

let system = ActorSystem.Create("FSharp")

let echoServer = 
spawn system "EchoServer"
<| fun mailbox ->
    let rec loop() =
        actor {
            let! message = mailbox.Receive()
            match box message with
            | :? string -> 
                printfn "Echo '%s'" message
                return! loop()
            | _ ->  failwith "unknown message"
        } 
    loop()

let boolval = system.EventStream.Subscribe(echoServer,typedefof<DeadLetterActorRef>)
echoServer.Tell("First Message")
echoServer.Tell("Second Message")
system.DeadLetters.Tell("Dead Message") 
Pankaj Chouthmal
  • 195
  • 1
  • 11
  • How exactly is it not working? – John Palmer May 25 '16 at 10:38
  • If it's not working the way it should, you probably didn't do something that you should have. :-) – Fyodor Soikin May 25 '16 at 11:00
  • I have modified above code slightly. @John whenever I am using DeadLetters.Tell(), messages are being sent to the deadletters actor. But in code I have subscribed to DeadLetters which means now it should send all dead letters messages to echoServer actor instead of DeadLetters – Pankaj Chouthmal May 25 '16 at 11:28
  • https://gist.github.com/DanielaSfregola/1cb7cb11a1b4f795853e .. I am trying to implement same scala code in F#, but I am not aware about Akka F# APIs for subscribing dead letters. – Pankaj Chouthmal May 25 '16 at 11:38

1 Answers1

3

When you subscribe to the event bus, you're subscribing to the type of message published to the bus. In the code you posted you registered the subscriber to the DeadLetterActorRef message, whereas dead letters are published in the form of DeadLetter messages. So in your case, you just need to change your subscription to

let boolval = system.EventStream.Subscribe(echoServer, typeof<DeadLetter>)
bruinbrown
  • 1,006
  • 2
  • 8
  • 13