Git Product home page Git Product logo

gokaf's People

Contributors

acjzz avatar hrmnjt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gokaf's Issues

Improvement ideas

First of all, thanks for writing that package.
I can already think about usage at work and would like to contribute to it.

I took time to read carefully the code, and i find it really clear, well written.
I still have few suggestions :

  • What about using Fuzz testing (https://github.com/google/gofuzz) ? I really believe it can make a lot of sense, more precisely inside the Topic related tests. Trying to test the handling workflow with a crazy amount of possible values can be really valuable, and can help us cover a lot of usability scenarios.

  • gokaf/topic.go

    Line 21 in 8a7e54a

    channelTopic = make(chan internalMessage, numConsumers[0])

Here, i feel the usage of variadic parameters coupled to the fact that the topic will only take the first argument if any exists can confuse the user at some point.
Of course, usage of variadic is really smart and cover the fact that golang does not offer optional argument capabilities, but my idea is to be more strict, and return an explicit error if more than one numConsumer is passed as argument.

  • I would also try to use as much early returns as i can, and avoiding else's as much as possible to make the code easier to ready and reduce cyclomatic complexity.

Examples :

break

} else {

For that last example, i would for instance find that smoother on eyes :

func (ge *Engine) AddTopic(name string, handler func(string, interface{}), numConsumers ...int) {
	name = strings.ToLower(name)
        if _, ok := ge.topics[name]; ok {   
              ge.logger.Warn("topic already exists")
              return
        }

        if len(numConsumers) > 0 {
                ge.topics[name] = NewTopic(ge.ctx, name, handler, numConsumers[0])
        } else {
                ge.topics[name] = NewTopic(ge.ctx, name, handler)
        }
        ge.topics[name].run()
}

Le me know what do you think.
Of course all of that are just details, but i just wanted to give my thoughts on that.

Another time, thanks for your awesome work.
I look forward to contribute, please create Issue when you have any feature idea, so as we can contribute.

Cheers !

New feature : Multi-handler topics.

Hello,
I'm thinking about implementing a kind of topic broadcaster feature.

The idea is adding a new type of topic (so will need to add a related interface), that will act as a topic container and will contain multiple classic (existing) topics. It can actually be compared to the exchange features that most of the message brokers systems has.
The final result would be a user publishing go that kind of topic, will see his stream message be processed by multiple handlers.

The usage would be something like :

func main() {
	ge := gokaf.NewEngine("MyEngine", logrus.DebugLevel)

        aragorn := NewTopic(ge.ctx, "aragorn", func(topic string, obj interface{}) {
            fmt.Printf("Consumed '%v' from topic aragorn", obj, topic)
        })
        legolas := NewTopic(ge.ctx, "legolas", func(topic string, obj interface{}) {
            fmt.Printf("Consumed '%v' from topic legolas", obj)
        })
       
	ge.AddTopicContainer("soldiers", aragorn, legolas)

	e := ge.Publish("soldiers", fmt.Sprintf("Message%d", i))
	if e != nil {
		fmt.Printf("publishing to topic 'soldiers', err: %v", e)
	}

	ge.Stop()
}

Of course the naming is weird here, but that's just a simple boilerplate code to express my idea.

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.