2016-10-03 9 views
16

इससे पहले कि मैं प्ले 2.5.x में माइग्रेट किया गया, मैंने अक्सर WebSocket.acceptWithActor का उपयोग किया। अब मैं अपने वेब सॉकेट को अलग-अलग इनपुट और आउटपुट का उपयोग करते समय खुले रहने के लिए नहीं मिल सकता, मेरे मामले में, इनपुट स्ट्रिंग है, आउटपुट जेएसवेल्यू है।PlayW.AxActor [स्ट्रिंग, जेएसवेल्यू] के बराबर प्ले 2.5.x क्या है?

प्ले 2.5.x से पहले मेरा रिसीवर:

object Application extends Controller { 
    def myWebSocket = WebSocket.acceptWithActor[String, JsValue] { request => 
     out => MyActor.props(out) 
} 

प्ले 2.5.x में मेरा रिसीवर:

@Singleton 
class Application @Inject() (implicit system: ActorSystem, materializer: Materializer) extends Controller { 
    implicit val messageFlowTransformer = 
        MessageFlowTransformer.jsonMessageFlowTransformer[String, JsValue] 
    def myWebSocket = WebSocket.accept[String, JsValue] { request => 
    ActorFlow.actorRef(out => MyActor.props(out)) 
    } 
} 

मेरी अभिनेता preStart में है बुलाया तुरंत postStop द्वारा पीछा किया, तो यह स्पष्ट रूप से सही नहीं है , लेकिन मुझे प्रलेखन में कोई समाधान नहीं मिल रहा है (https://www.playframework.com/documentation/2.5.x/ScalaWebSockets)। यदि मैं WebSocket.accept[String, String] का उपयोग करता हूं तो सॉकेट खुला रहता है।

मैं क्या गलत कर रहा हूं?

ActorFlow.actorRef[String, JsValue](out => 
     MyActor.props(
     out, 
     ... 
    ) 
    ).map(_.toString) 

इस के साथ आप shouln't एक कस्टम messageflowtransformer को परिभाषित करने और अभिनेता के स्तर पर आप अभी भी तार प्राप्त हो जाएगा और JsValues ​​लौट सकते हैं:

+0

हाय, क्या आपको इसका समाधान मिल गया है? – SergiGP

+0

दुर्भाग्यवश नहीं, मैं 'WebSocket.accept [स्ट्रिंग, स्ट्रिंग]' –

+0

का उपयोग करके गया, मेरे उत्तर पर एक नज़र डालें, यह गंदा है लेकिन शायद यह आपके लिए काम कर सकता है :) – SergiGP

उत्तर

1

मैं एक workarround

मेरे नियंत्रक पाया है।

संबंधित मुद्दे