mercredi 15 mars 2017

golang dispatcher using map and channels

I try design a dispatcher using go in a concurrency situation, the dispatcher needs to dispatch the message to its dedicated worker which only treat one kind of messages (or workers), ex:

  • worker type A only processes the message type A
  • worker type B only processes the message type B
  • etc.,

As I can add/remove dynamically the dedicated worker treating different types of messages. Now I need a message pattern to do so with only goroutine and channel. I plan to have a channel -- a pool of same type workers, and put the pools in a map, so I can distribute message by type according to the keys in map, and the same type of workers can process the same type of messages concurrently. I am not sure if it is a better design or not, any suggestion?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire