2015-06-26 20 views
5

Tôi có một diễn viên với hành vi:Outgoing dòng kết nối đóng

def receive: Receive = { 
    case Info(message) => 
     val res = send("INFO:" + message) 
     installAckHook(res) 
    case Warning(message) => 
     val res = send("WARNING:" + message) 
     installAckHook(res) 
    case Error(message) => 
     val res = send("ERROR:" + message) 
     installAckHook(res) 
    } 

private def installAckHook[T](fut: Future[T]): Unit = { 
    val answerTo = sender() 

    fut.onComplete { 
     case Success(_) => answerTo ! "OK" 
     case Failure(ex) => answerTo ! ex 
    } 
    } 


    private def send(message: String): Future[HttpResponse] = { 
    import context.system 
    val payload: Payload = Payload(text = message, 
     username = slackConfig.username, icon_url = slackConfig.iconUrl, 
     icon_emoji = slackConfig.iconEmoji, channel = slackConfig.channel) 
     .validate 
    Http().singleRequest(RequestBuilding.Post(slackConfig.hookAddress, payload)) 
    } 

Và một thử nghiệm

val actorRef = system.actorOf(SlackHookActor.props(SlackEndpointConfig(WebHookUrl,iconEmoji = Some(":ghost:")))) 
actorRef ! Error("Some error message") 
actorRef ! Warning("Some warning message") 
actorRef ! Info("Some info message") 
receiveN(3) 

và trong phương pháp afterAll() tôi làm một shutdown trên hệ thống diễn viên sử dụng TestKit.

Nó hoạt động, yêu cầu làm cho nó đến máy chủ, nhưng có những sai sót từ AKKA suối phần:

[ERROR] [06/26/2015 11:34:55.118] [SlackHookTestingSystem-akka.actor.default-dispatcher-10] [ActorSystem(SlackHookTestingSystem)] Outgoing request stream error (akka.stream.AbruptTerminationException) 
[ERROR] [06/26/2015 11:34:55.120] [SlackHookTestingSystem-akka.actor.default-dispatcher-13] [ActorSystem(SlackHookTestingSystem)] Outgoing request stream error (akka.stream.AbruptTerminationException) 
[ERROR] [06/26/2015 11:34:55.121] [SlackHookTestingSystem-akka.actor.default-dispatcher-8] [ActorSystem(SlackHookTestingSystem)] Outgoing request stream error (akka.stream.AbruptTerminationException) 

Có vẻ như kể từ khi tôi có một tương lai hoàn thành việc kết nối gửi đi nên đã đóng cửa, như vậy là đây là một lỗi hoặc tôi thiếu sth?

+0

Tôi có cùng một vấn đề. Cảm ơn vì bất kì sự giúp đỡ. – jiangok

+0

Chúng ta cần một mô hình tắt cho dòng akka. Kể từ khi các diễn viên dòng chảy là tiềm ẩn, tôi không biết nếu nó là đúng để áp dụng các kỹ thuật được đề cập trong letitcrash.com/post/30165507578/shutdown-patterns-in-akka-2. – jiangok

+0

Bị bỏ rơi vì lười biếng. Cả tiêu đề cũng như các thẻ đều không đưa ra bất kỳ ngữ cảnh hữu ích nào. – mc0e

Trả lời

2

Bạn cũng cần phải tắt hồ kết nối http, một cái gì đó giống như

Http().shutdownAllConnectionPools().onComplete{ _ => 
    system.shutdown() 
} 

Có lẽ AKKA http testkit cung cấp một số những người giúp đỡ

+5

Điều này bắt đầu tăng một câu hỏi phải đóng những gì? Chúng tôi có hồ bơi kết nối, hệ thống diễn viên và diễn viên materialiser. Vì vậy, nó phải giống như gần hồ bơi http -> gần materialize -> đóng hệ thống? – almendar

Các vấn đề liên quan