Coder Social home page Coder Social logo

Comments (4)

rogeralsing avatar rogeralsing commented on June 20, 2024

If we go for this approach, we also need to solve how to talk to PID's from outside an actor.
this could be done by having a Tell func directly in actor

actor.Tell(pid, msg)

That would be a "contextless" Tell.
If you have some sort of context, for example Zipkin data, and you want to call into the actor world using this context.
We could have something like this:

ctx := actor.NewRootContext( whatever context data)
defer ctx.Close()
ctx.Tell(pid, msg)

I think this would be fairly clean, even if this approach is more verbose than what we have currently.

from protoactor-go.

cpx86 avatar cpx86 commented on June 20, 2024

I'm not too familiar with how the context and PID interact yet, but from a user perspective I think it's important that there are as few ways as possible of doing something, preferably just one if possible.

Would it be a bad coupling if the PID knew about the context it belongs to? So calling pid.Tell would notify the context of the Tell operation, so it can do tracing or whatever it is it needs to do.

from protoactor-go.

rogeralsing avatar rogeralsing commented on June 20, 2024

making the PID know about the current context is possible in e.g C# using AsyncLocal and all that black magic.
It is less doable in Go as Go has its own concept of Go routines, there are hacks to peek into thread local like storage for this, but I don't want to go there.

(The same PID could flow through multiple contexts in e.g. a message, so it is not tied to the context in any way)

Another option could be to provide the context into the pid.Tell(msg, context)

that would be less intrusive on the current design, right?
the last context param might be an arglist of context providers. passing nothing would mean telling from the root context.

Just tossing around ideas here

from protoactor-go.

rogeralsing avatar rogeralsing commented on June 20, 2024

Discussed API:

context.Tell(pid, message)

We could either go for:
context.Tell(pid, message)
context.TellRaw(pid, bytes) (or somilar)

or
context.Tell(pid, Message{Object: msg})
context.Tell(pid, Message{Bytes: bytes})

Related tasks

  • Introducing a message envelope type carrying message headers, this type can also replace the current messageSender type

e.g.

type struct Message {
     Headers MessageHeaders // string -> string map
     Object interface{} 
     Bytes []byte
     Sender *PID //this could be tricky as PID lives in actor package
}
  • Make all queues carry this message envelope instead of interface{}
  • Introduce way of reading message headers from actor Context
  • Introduce outbound middleware allowing code to read from actor context and write to outgoing message headers
  • Introduce a RootContext which can be used when integrating with actors from the outside world

e.g.

func main() {
    pid := ...
    ...
    ctx := NewRootContext()
    ctx.Headers().Add("TraceID", "123") //the rootcontext can be configured with some initial values
    //or possibly, root context headers should be set on creation?

    ctx.Tell(pid, message)
}

One question we need to decide on,
Do we keep Tell on the PID for convenience? e.g. when interacting with actors from the outside.
or do we provide a default empty root context through actor.Tell or something similar?

from protoactor-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.