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 Pub/Sub pattern for RabbitMQ #25

Open
Tracked by #22
derevnjuk opened this issue Mar 6, 2023 · 0 comments · May be fixed by #31
Open
Tracked by #22

Implement Pub/Sub pattern for RabbitMQ #25

derevnjuk opened this issue Mar 6, 2023 · 0 comments · May be fixed by #31
Assignees
Labels
Type: enhancement New feature or request.

Comments

@derevnjuk
Copy link
Member

derevnjuk commented Mar 6, 2023

Each event type has a related channel to get events from RabbitMQ. You can then have as many event handlers per channel and event type as needed.

The register method accepts a type of EventHandler, adding that event handler to the list of handlers that each event can have. If the bus is not subscribed to the event, it creates a new channel with a routing key using an event type so it can receive events when that event is published from any other service.

type IssueFoundHandler struct {}

func (h *IssueFoundHandler) Handle(message Message) (any, error) {
    // implementation
}

// ...

eventBus.Register("IssueFound", &IssueFoundHandler{})

Once it is done, the bus will register corresponding handlers to listen to particular events. When any message of the expected type arrives, the bus invokes the handle method of the event handler that is passed to it.

Make sure that a single handler can handle multiple different events, and multiple different handlers can handle events.

@derevnjuk derevnjuk self-assigned this Mar 6, 2023
@derevnjuk derevnjuk added the Type: enhancement New feature or request. label Mar 6, 2023
derevnjuk added a commit that referenced this issue Mar 14, 2023
derevnjuk added a commit that referenced this issue Mar 14, 2023
@derevnjuk derevnjuk linked a pull request Mar 14, 2023 that will close this issue
derevnjuk added a commit that referenced this issue Mar 14, 2023
derevnjuk added a commit that referenced this issue Mar 14, 2023
derevnjuk added a commit that referenced this issue Mar 14, 2023
derevnjuk added a commit that referenced this issue Apr 10, 2023
derevnjuk added a commit that referenced this issue Apr 10, 2023
derevnjuk added a commit that referenced this issue Apr 10, 2023
derevnjuk added a commit that referenced this issue Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant