Giter Site home page Giter Site logo

Comments (5)

mustafaturan avatar mustafaturan commented on May 28, 2024

You can register as many handler as you want: https://godoc.org/github.com/mustafaturan/bus#Bus.RegisterHandler

from bus.

navono avatar navono commented on May 28, 2024

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.

mustafaturan avatar mustafaturan commented on May 28, 2024

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.

navono avatar navono commented on May 28, 2024

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.

mustafaturan avatar mustafaturan commented on May 28, 2024

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 and event.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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.