Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

About V300 #174

Capybara-1 started this conversation in General
Feb 18, 2024 · 18 comments · 7 replies
Discussion options

Hi, I saw the submission of the new V300 branch. Is there any relevant documentation to check?

You must be logged in to vote

Replies: 18 comments · 7 replies

Comment options

Hi,
Its in progress now and will be published along with the release 3.0.

You must be logged in to vote
1 reply
@Capybara-1
Comment options

When will version 3.0 be released?

Comment options

You must be logged in to vote
1 reply
@halturin
Comment options

Could you please share the way you use it?

Comment options

You must be logged in to vote
0 replies
Comment options

It is not allowed to use gen.Process outside of the actor and must be used within Handle* callbacks only (or the same goroutine)

You must be logged in to vote
0 replies
Comment options

here is an example you might find useful https://github.com/ergo-services/examples/tree/v300

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

However, timeout can also occur when using it internally.

default timeout for Call requests is 5 seconds. Make sure your process (that handles this request) is able to handle it in time.

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@halturin
Comment options

please, share your HandleCall on the remote process.

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

Thank you for your reply and answer. I need to check to see if there is something wrong with the way I am using it.

You must be logged in to vote
0 replies
Comment options

demo.go:

package main

import (
	"time"

	"ergo.services/ergo"
	"ergo.services/ergo/act"
	"ergo.services/ergo/gen"
	"ergo.services/ergo/net/edf"
	"ergo.services/logger/colored"
)

type doCallLocal struct{}
type doCallRemote struct{}

type MyMessage struct {
	MyBool   bool
	MyString string
}

func main() {
	var options gen.NodeOptions

	// disable default logger to get rid of multiple logging to the os.Stdout
	options.Log.DefaultLogger.Disable = true

	// add logger "colored".
	loggercolored, err := colored.CreateLogger(colored.Options{})
	if err != nil {
		panic(err)
	}
	options.Log.Loggers = append(options.Log.Loggers, gen.Logger{Name: "cl", Logger: loggercolored})

	options.Log.Level = gen.LogLevelInfo
	// options.Log.Level = gen.LogLevelTrace

	// set network cookie
	options.Network.Cookie = "123"
	// to be able to use self-signed cert
	options.Network.InsecureSkipVerify = true

	// starting node1
	node1, err := ergo.StartNode("node1@localhost", options)
	if err != nil {
		panic(err)
	}

	// register network messages
	if err := edf.RegisterTypeOf(MyMessage{}); err != nil {
		panic(err)
	}

	// use the same options, but remove loggers we added for node1 to use the default one in node2
	options.Log.Loggers = nil
	options.Log.DefaultLogger.Disable = false
	node2, err := ergo.StartNode("node2@localhost", options)
	if err != nil {
		panic(err)
	}
	defer node2.StopForce()

	node2.SpawnRegister("b", factoryB, gen.ProcessOptions{})

	node1.SpawnRegister("b", factoryB, gen.ProcessOptions{})
	node1.SpawnRegister("a", factoryA, gen.ProcessOptions{})

	node1.Send(gen.Atom("a"), doCallLocal{})

	node1.Wait()
}

//
// Actor A
//

func factoryA() gen.ProcessBehavior {
	return &actorA{}
}

type actorA struct {
	act.Actor
}

func (a *actorA) Init(args ...any) error {
	a.Log().Info("started A process on %s: %s", a.Name(), a.Node().Name())
	return nil
}

func (a *actorA) HandleMessage(from gen.PID, message any) error {
	switch message.(type) {
	case doCallLocal:
		local := gen.Atom("b")
		if result, err := a.Call(local, MyMessage{MyString: "abc"}); err == nil {
			a.Log().Info("received result: %#v", result)
		} else {
			a.Log().Error("call local process failed: %s", err)
		}
		a.SendAfter(a.PID(), doCallRemote{}, time.Second)
		return nil

	case doCallRemote:
		remote := gen.ProcessID{Name: "b", Node: "node2@localhost"}
		if result, err := a.Call(remote, MyMessage{MyBool: true, MyString: "def"}); err == nil {
			a.Log().Info("received result: %#v", result)
		} else {
			a.Log().Error("call remote process failed: %s", err)
		}

		a.SendAfter(a.PID(), doCallLocal{}, time.Second)
		return nil

	}

	a.Log().Error("unknown message %#v", message)
	return nil
}

//
// Actor B
//

func factoryB() gen.ProcessBehavior {
	return &actorB{}
}

type actorB struct {
	act.Actor
}

func (b *actorB) Init(args ...any) error {
	b.Log().Info("started B process on %s: %s", b.Name(), b.Node().Name())
	return nil
}

func (b *actorB) HandleCall(from gen.PID, ref gen.Ref, request any) (any, error) {
	switch r := request.(type) {
	case MyMessage:
		b.Log().Info("received MyMessage request from %s: %#v", from, r)
		return true, nil
	}

	b.Log().Info("received unknown request: %#v", request)
	return false, nil
}

go.mod

module demo

go 1.21.6

require (
	ergo.services/ergo v1.999.225-0.20240303205107-3b21499342ce
	ergo.services/logger v0.0.0-20240221211214-98de4c9ff50e
)

require (
	github.com/fatih/color v1.16.0 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.20 // indirect
	golang.org/x/sys v0.14.0 // indirect
)

result:
image

You must be logged in to vote
3 replies
@Capybara-1
Comment options

Thank you very much for this demo, and I tried running it. It works perfectly fine. However, in my testing environment, I didn’t start two nodes in the same process. Instead, I started one Node in each of two different processes to make an inter-process call. In this setup, actor.Send works without any issues, but actor.Call encounters problems. The names of the two nodes are 10001@127.0.0.1 and 10003@127.0.0.1. I’m not sure if the issue arises from how I started the two node processes or something else. Thank you for your response.

@halturin
Comment options

it is not a problem to split it out into two different modules, but make sure to register the message type (edf.RegisterTypeOf(...)) of your message on both sides (if this message is declared in the module of node1, you should import it and register exactly this type).

@Capybara-1
Comment options

I simply used the string type.

Comment options

also added this example here https://github.com/ergo-services/examples/tree/v300

You must be logged in to vote
0 replies
Comment options

截屏2024-03-05 22 52 11
截屏2024-03-05 22 53 32
截屏2024-03-05 22 53 48

This is my calling process. As you can see, when HandleCall actively throws an error, it will be returned to the caller. However, at this point, the caller’s Call is still blocked until it times out. In other words, there is no issue with network connectivity or the logic of the Call; it’s just unclear why the correct response is not being received.

You must be logged in to vote
0 replies
Comment options

截屏2024-03-05 22 56 19

截屏2024-03-05 22 58 14

This is the code that does not actively throw an error. As you can see in the console, it did not return “try reply remote call” as expected, but instead threw a timeout.

You must be logged in to vote
0 replies
Comment options

Just fixed an issue that might be related to your problem. Pull the latest changes in v300.

You must be logged in to vote
0 replies
Comment options

I've been reading and playing with the v3 examples, those meta processes injected on the endpoint to then use a pool (inited on the supervisor) then a web worker that handle the methods... it's so clever! I love it!

Screenshot 2024-07-06 at 10 26 35 AM
You must be logged in to vote
1 reply
@halturin
Comment options

thanks.
PS just noticed some misprints in the comments :). will fix them before the release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.