Code Monkey home page Code Monkey logo

Comments (7)

GeorgeMac avatar GeorgeMac commented on June 16, 2024

I made a suggestion in #10 that you actually treat every call to Receive as a subscription. As it is trivial in Go to then take the channel and use it as a work queue by sharing that channel. Where as, if you treated Receive as work-queue like, then every consumer would get the same channel and wouldn't be able to choose to have subscription semantics. Well... without then copying each message and fanning out themselves.

from vice.

HeavyHorst avatar HeavyHorst commented on June 16, 2024

At the moment every call to Receive("something") would get the same channel in every implementation.
So if we are using just a single transport on a single node we have already work queue semantics.

But if we create more than one transport or let our program run on more than one node we get sometimes pub/sub and sometimes work queue behaviour.

Receiver.go

package main

import (
	"fmt"

	vn "github.com/matryer/vice/queues/redis"
)

func main() {
	nt := vn.New()
	defer nt.Stop()

	rc := nt.Receive("test123")

	for i := 0; i < 5; i++ {
		v := <-rc
		fmt.Println(string(v))
	}
}

Sender.go

package main

import (
	"fmt"
	"time"

	vn "github.com/matryer/vice/queues/redis"
)

func main() {
	nt := vn.New()
	defer nt.Stop()

	sc := nt.Send("test123")

	for i := 0; i < 5; i++ {
		sc <- []byte(fmt.Sprintf("%d Hallo", i))
		time.Sleep(1 * time.Second)
	}
}

Redis:

screenshot1

NSQ:

screenshot2

from vice.

GeorgeMac avatar GeorgeMac commented on June 16, 2024

I suppose vice is intended to be a queue and not pub sub. So queue semantics by default makes sense over subscription.

from vice.

HeavyHorst avatar HeavyHorst commented on June 16, 2024

I agree

from vice.

matryer avatar matryer commented on June 16, 2024

Right, Vice is a queue. It's tough to think of a way to properly test that stuff; so I think we just have to be careful about it in the implementations.

Do we need to tweak anything here?

from vice.

HeavyHorst avatar HeavyHorst commented on June 16, 2024

The nats implementation just needs to use QueueSubscribe instead of Subscribe.
I'm sure redis can also be used as a work queue.

from vice.

HeavyHorst avatar HeavyHorst commented on June 16, 2024

Solved with #29 and #28

from vice.

Related Issues (20)

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.