hemerajs/hemera

Publish to many queue group?

zhaoyao91 opened this issue · 3 comments

According to the docs, we can publish to many subscriber, or publish to only one queue group, but, how to publish to many queue group?

In other word, there are many roles listen to the same topic and react differently, but we wish to clustering a role with many instances, so, a publication should be pushed to all the subscriber roles, but only one instance of each role will receive it.

I have had a quick view of the source code, guessing that I may code as below:

// group-1 with many instances
hemera.add({
  $queue: 'group-1'
  topic: 'sth-happened'
}, handler)

// group-2 with many instances
hemera.add({
  $queue: 'group-2'
  topic: 'sth-happened'
}, handler)

hemera.act({
  $pubsub: true,
  topic: 'sth-hanppened'
})

Does this implement what I issued before?

Thanks.

You can't publish to a specific queue because many subscribers builds a queue group. The publisher is not aware of that. If you have one queue group and many instances (default) the request will be load balanced across all subscribers. If you have a custom queue group with the same topic the request will arrive one instance doesnt matter how much this service is scaled but if you have many different queue groups per add with the same topic the request will load balanced for each group so multiple subscriber will receive that event.

Default: topic = queue-group

add('topic:math,cmd:add')

Worker Queue: If you scale your service the request will receive only one instance. (Doesnt matter whether pubsub or request/reply)

add('topic:math,cmd:add,queue$:test')
add('topic:math,cmd:add,queue$:test')

Custom queue per add: The request will receive at least one time for each custom queue-group

add('topic:math,cmd:add,queue$:test1')
add('topic:math,cmd:add,queue$:test2')

Closed due to inactivity.