Pergunta de entrevista da empresa Amazon

Design a "Subscriber - Broker - Publisher" architecture (a) running on a machine; (b) running on a cluster. Write the code for the 3 classes. Details: there are Events, specified by an "event type" and a blob of detailed info. Each subscriber subscribes with a Broker for a certain event type that it wants to get. Subscribers send events to the broker, and the relevant subscribers need to be notified.

Resposta da entrevista

Sigiloso

3 de fev. de 2011

The observer and observable design pattern can come in handy here. Or if you wanted to do it without the interfaces, simply maintain a list of all publishers in the broker and a map of which subscibers can be attributed to a particular publisher. then whenever there is an event from the publisher, simply notify all the subcribers for that publisher.