Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:38:47+00:00 2026-06-11T17:38:47+00:00

For reference, this question has roots from Scala method performance (collect or foreach or

  • 0

For reference, this question has roots from Scala method performance (collect or foreach or other) looping through sockets?

I’m storing a reference to a websocket inside an actor, and then subscribing that actor to an Akka EventStream:

val socketActor = system.actorOf(Props(new Actor {
  val socket = WebSocketConnection

  def receive = {
    case d: AppMessage ⇒ socket.send(d)
  }
}))
system.eventStream.subscribe(socketActor, classOf[AppMessage])

What bugs me is that the only classifier I can make with an EventStream is a class type. So if you want to route messages to different actors, say based on userId, do you need to create multiple EventStreams and manually build an EventBus or is there something here that I am missing?

It would be nice if I could do something simply like:

system.eventStream.subscribe(socketActor, Map("userId" -> userId, "teamId" -> teamId) )

This may be simply a conceptual issue, as I’m not quite sure what EventStream represents.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:38:49+00:00Added an answer on June 11, 2026 at 5:38 pm

    This was my solution based on the ActorEventBus based on this Gist: https://gist.github.com/3757237

    I found this to be a lot more maintainable than dealing with EventStreams. Perhaps multiple EventStreams will be needed in the future, but at this point it readily supports current infrastructure.

    MessageBus

    First, the MessageBus that handles the outgoing messages to sockets wrapped in actors, based on PubSub channels:

    case class MessageEvent(val channel:String, val message:String)
    
    /**
     * message bus to route messages to their appropriate contexts
     */
    class MessageBus extends ActorEventBus with LookupClassification {
    
        type Event = MessageEvent
      type Classifier = String
    
      protected def mapSize(): Int = {
        10
      }
    
      protected def classify(event: Event): Classifier = {
        event.channel
      }
    
      protected def publish(event: Event, subscriber: Subscriber): Unit = {
        subscriber ! event
      }
    
    }
    
    
    object MessageBus {
    
      val actorSystem = ActorSystem("contexts")
      val Bus = new MessageBus
    
      /**
       * create an actor that stores a browser socket
       */
      def browserSocketContext(s: WebSocketConnection, userId: Long, teamId: Long) = {
        val subscriber = actorSystem.actorOf(Props(new BrowserSocket(s,userId,teamId)))
    
        Bus.subscribe( subscriber, "/app/socket/%s" format s.toString)
        Bus.subscribe( subscriber, "/app/browser/u/%s" format userId )
        Bus.subscribe( subscriber, "/app/browser/t/%s" format teamId )
        Bus.subscribe( subscriber, "/app/browser" )
      }
    }
    

    Socket Access with Actors

    Here’s the actor that actually contains the socket:

    /**
     * actor wrapping access for browser socket
     */
    class BrowserSocket(
      val s: WebSocketConnection,
      val userId: Long,
      val teamId: Long
    
    ) extends Actor {
    
      def receive = {
        case payload:MessageEvent => 
          s.send(payload.message)
    
        case ping:MessagePing =>
          s.ping(ping.data)
    
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is with reference to the below question: Execute program from within a C
This question has been asked before, mainly with reference to ListActivity, and therefore I
So I know this question has been asked 20 other times and 20 different
In reference with this question We have a header with a date picked component
With the reference to this question:- JavaScript -Change CSS color for 5 seconds Working
Reference: This is a self-answered question. It was meant to share the knowledge, Q&A
EDIT: This question is about finding definitive reference to MySQL syntax on SELECT modifying
Somebody ask me this question today . What is the need of reference in
I'm using Alberto Santini's solution to this question to get a spiral grid reference
In reference to this answer to a Stack Overflow question : what is bench-testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.