So I am not sure but I think this is doing what I wanted to accomplish, the 
flow is 

public Flow<Message, Message, NotUsed> createWebSocketFlow() {
        
        pub = system.actorOf(Props.create(AbsPublisher.class));
        
        System.out.println("out actor ref: " + pub.path().name());
        
        // response
        Source<Message, NotUsed> source = 
                Source.<Outgoing>actorRef(5, OverflowStrategy.fail())
                        .map((outgoing) -> (Message) 
TextMessage.create(outgoing.message))
                        .<NotUsed>mapMaterializedValue(destinationRef -> {
                            pub.tell(new 
OutgoingDestination(destinationRef), ActorRef.noSender());
                    return NotUsed.getInstance();
        });
        // request
        Sink<Message, NotUsed> sink = 
                Flow.<Message>create()
                    .map((msg) -> new 
Incoming(msg.asTextMessage().getStrictText()))
                    .to(Sink.actorRef(pub, PoisonPill.getInstance()));
        
        return Flow.fromSinkAndSource(sink, source);
    }

where Incoming and Outgoing are just simple classes that contain strings, 
and outgoingdestination contains an actorref
AbsPublisher is an AbstractActorPublisher with a receive that handles the 
outgoingdestination setup and message passing (via .tell to the destination)

so I can call in my main class:
     system.eventStream().publish(new Incoming("test"), PubRef);

and this will send the message from the server to the client (in my tests I 
generate a message from the main of the websocketapp class and it shows up 
on the client side like I want). So I should be able to pack this message 
with my json and go from there. I copied most of this code from an answer 
here 
<https://groups.google.com/forum/#!searchin/akka-user/akka$20java$20websocket%7Csort:relevance/akka-user/zOI6qdg_wqc/bM57ylHTBQAJ>
 by 
Johan Andren.

This might not be the best solution but it seems to do what I need. If 
anyone else has some suggestions I am still all ears, the flow aspect is 
still hard for me to wrap my head around.

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to