Comments (5)
You can register as many handler as you want: https://godoc.org/github.com/mustafaturan/bus#Bus.RegisterHandler
from bus.
Maybe I didn't describe it clearly.
As the bus-sample-project, if modity counter.go
file like this:
// Start registers the counter handler
func Start(wg *sync.WaitGroup) {
b := config.Bus
h := bus.Handler{Handle: count, Matcher: ".*"}
b.RegisterHandler(worker, &h)
fmt.Printf("Registered counter handler...\n")
h2 := bus.Handler{Handle: count2, Matcher: ".*"}
b.RegisterHandler(worker, &h2)
wg.Add(1)
go increment(wg)
}
count
handler will not be called anymore because of
handlers map[string]*Handler
is not a list, it will replace with after new one.
from bus.
What do you think not to use the same name for the handlers. Instead of passing the first arg as ‘worker’ to both, you can use any different name. ‘name’ should be unique per handler and it is not a topic name
from bus.
Imagine a scenario where an http service receives a user request. After the service receives the request, it needs to send the same request message to a different service module for processing. At this time, it is different processing for the same topic name, instead of creating two different names.
from bus.
I am not sure if I understand correctly but I think you are trying register the handler dynamically on run time for each http request. If this is correct here is my suggestion:
- Handlers should be registered once the app runs then they should listen for events for performance reasons.
- If a handler needs to handle http request, the data can be passed with both of the
context
andevent.Data
to distinguish context specific logic. - If you need dynamic handlers then the way is to provide a unique naming on handlers (not for the topics).
- Handler name and topic names are different concepts. Topic names are not coupled to handler names and handlers names are not coupled to topic names.
from bus.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bus.