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

Implement Event Broker for Async Events and Responses #28

Closed
wants to merge 4 commits into from
Closed

Implement Event Broker for Async Events and Responses #28

wants to merge 4 commits into from

Conversation

mind-ar
Copy link
Contributor

@mind-ar mind-ar commented Mar 25, 2021

Hi, this pull request implements asynchronous events in AMI.
This should fix issue #22
I have not much experience in contributions, so any recommendation is welcome
BTW, not English speaker here :)

@mind-ar
Copy link
Contributor Author

mind-ar commented Mar 25, 2021

This should fix #14 too

/*
* El broker de eventos permite leer los eventos de asterisk y distribuirlos entre los subscriptores
* Esta implementación está basada en https://github.com/kljensen/golang-html5-sse-example/blob/master/server.go
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider writing all comments in English

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@@ -18,6 +18,7 @@ type Socket struct {
incoming chan string
shutdown chan struct{}
wg sync.WaitGroup
events *EventsBroker
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see why it's necessary have an event broker in the socket struct.


import (
"context"
_log "github.com/rs/zerolog/log"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all log messages, before submit the patch. The main idea of goami is working as a library and returns all errors as a normal return value

return nil, err
}
}
actionID := rsp.Get("ActionID")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that ActionID should be the same of included in the request and the verification must be included as fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will create an new pull request with this fix

```
### Advantages of using Event Broker
* Multiple subscribers (ie: http request por events)
* The Action ID from response is compared width the action ID from command, so you have accurate response
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with pros, but the event broker IMHO should be implemented at the top of library, not inside it.
For example:
https://github.com/heltonmarx/goami/blob/master/example/asterisk.go#L90

Consuming the ami.Events(ctx, socket) by a dedicated socket.
And using another socket connection to submit commands only.

Creating a collection of sockets + events dedicated to your application, but not necessarily included to the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main reason why I put the event broker inside the library was because of the risk of a command "stealing" the response belonging to another command, especially in multi-client environments (rest api).
Let me figure how to solve that problem without including an event broker.

@mind-ar
Copy link
Contributor Author

mind-ar commented Mar 28, 2021

ill close this pull request for making some fixes to the code.

@mind-ar mind-ar closed this Mar 28, 2021
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.

2 participants