Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc:cast/4 from Erlang/OTP24 to Ergo does not work #127

Closed
wants to merge 1 commit into from

Conversation

leonlee2013
Copy link

Erlang project has rpc:cast/4 which needs to be compatible with ergo.
Here is the test code

package main

import (
	"flag"
	"fmt"

	"github.com/ergo-services/ergo"
	"github.com/ergo-services/ergo/etf"
	"github.com/ergo-services/ergo/node"
)

var (
	ServerName string
	NodeName   string
	Cookie     string
)

func init() {
	flag.StringVar(&ServerName, "server", "example", "server process name")
	flag.StringVar(&NodeName, "name", "go_node1@127.0.0.1", "node name")
	flag.StringVar(&Cookie, "cookie", "go_erlang_cookie", "cookie for interaction with erlang cluster")
}

func main() {
	flag.Parse()

	fmt.Println("")
	fmt.Println("to stop press Ctrl-C")
	fmt.Println("")

	node, err := ergo.StartNode(NodeName, Cookie, node.Options{})
	if err != nil {
		panic(err)
	}

	testFun1 := func(a ...etf.Term) etf.Term {
		fmt.Printf("go handle --->>> %#v\n", a)
		return a[len(a)-1]
	}
	if e := node.ProvideRPC("testMod", "testFun", testFun1); e != nil {
		panic(err)
	}

	fmt.Println("Start erlang node with the command below:")
	fmt.Printf("    $ erl -name %s -setcookie %s\n\n", "erl-"+node.Name(), Cookie)

	node.Wait()
}

Before fixing the bug of rpc:call/4

#Erlang input and output:
(erl-go_node1@127.0.0.1)51> rpc:cast('go_node1@127.0.0.1', testMod, testFun, [a,"hello",111]).
true

#Log output of Go
2022/12/07 21:23:02 WARNING! Server [rex] HandleCast: unhandled message etf.Tuple{"cast", "testMod", "testFun", etf.List{"a", "hello", 111}, etf.Pid{Node:"erl-go_node1@127.0.0.1", ID:0x48, Creation:0x638455dd}}

After fixing the bug of rpc:call/4

#Erlang input and output:
(erl-go_node1@127.0.0.1)51> rpc:cast('go_node1@127.0.0.1', testMod, testFun, [a,"hello",111]).
true

#Log output of Go
go handle --->>> []etf.Term{"a", "hello", 111}

@halturin halturin deleted the branch ergo-services:v221 February 1, 2023 09:38
@halturin halturin closed this Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants