Originate / exocom

communication infrastructure for AI-native application ecosystems
MIT License
2 stars 1 forks source link

Introduce Send with callback or response functionality in go #150

Closed stefansavev-o closed 7 years ago

stefansavev-o commented 7 years ago

The livescript send functionality supports a callback like this:

exoRelay = new ExoRelay exocom-host: host, exocom-port: port, role: role
exoRelay.send 'message.request {field1:..., field2:...}, (_, {outcome}) ->
  console.log "'message.response '#{outcome}'"

Introduce a similar functionality. I propose the following signature

func (e *ExoService) SendWait(message exorelay.MessageOptions, timeout time.Duration) (*structs.Message, error) {
// use the message id to pair the request to the response
// return the response, a timeout or a connection error
}

Proposed Usage:

    payload := make(map[string]interface{})
    payload["query_param_1"] = p1
    payload["query_param_2"] = p2
    msg := exorelay.MessageOptions{Name: "message.request", Payload: payload}
    replyMsg, err := exoservice.GetService().SendWait(msg, time.Duration(500*time.Millisecond))
    if err != nil {
        return nil, err
    }
        return replyMsg, nil
charlierudolph commented 7 years ago

Are you asking for that functionality in exorelay or exoservice? You point to exorelay in js but then want this implement in exoservice.

Also for the exoservice, there currently isn't an exposed send function. There is only send function passed to the message handlers. Is that where you would want this function?

stefansavev-o commented 7 years ago

In ExoService. I can add sample code with my solution if you are interested.

charlierudolph commented 7 years ago

Yeah that would be helpful

charlierudolph commented 7 years ago

Also one of my questions wasn't answered

Also for the exoservice, there currently isn't an exposed send function. There is only send function passed to the message handlers. Is that where you would want this function?

stefansavev-o commented 7 years ago

That will work for my use cases. but the flow is like this

onHandler(msg){ result := await call exosphere with another message (similar to NodeJs and Python await, although go does not have that) do something with result return from the handler }

charlierudolph commented 7 years ago

Okay cool. That should be easy enough to add

stefansavev-o commented 7 years ago

I encountered a dead lock when I implemented this and had to put the handler on a go routine. So deadlocks is something to watch for.

charlierudolph commented 7 years ago

@stefansavev-o a change @kevgo wants to make is removing responseTo and adding activityId where a message basically starts a thread which any service can reply to. We can introduce a WaitForMessage method that allows you to pass in an activityId and a message name to wait for a specific reply

stefansavev-o commented 7 years ago

ok, so it would be something like

activityId := Send(...)
response: = WaitFor(activityId, msgName)

Ok, this will be useful. If you generalize WaitFor to multiple activities/messages also very useful.

charlierudolph commented 7 years ago

blocked by #166