Publish-subscribe, Event brokers

28
Publish-subscribe, Event brokers INF 123 – Software architecture [email protected] 1

description

Publish-subscribe, Event brokers. INF 123 – Software architecture [email protected]. Outline. Pubsub Event brokers. pubsub. Newspaper distribution. Newspaper companies publish newspapers Readers (un)subscribe to a company for a newspaper Company sends newspaper to its subscribers. - PowerPoint PPT Presentation

Transcript of Publish-subscribe, Event brokers

Page 1: Publish-subscribe, Event  brokers

1

Publish-subscribe,Event brokers

INF 123 – Software [email protected]

Page 2: Publish-subscribe, Event  brokers

2

Outline

• Pubsub• Event brokers

Page 3: Publish-subscribe, Event  brokers

3

PUBSUB

Page 4: Publish-subscribe, Event  brokers

4

Newspaper distribution

• Newspaper companies publish newspapers• Readers (un)subscribe to a company for a

newspaper• Company sends newspaper to its subscribers

Page 5: Publish-subscribe, Event  brokers

5

Newspaper distribution

Page 6: Publish-subscribe, Event  brokers

6

Stock exchange

• Jobs wants to buy AAPL below $30• Gates wants to buy MSFT below $40• Buffett wants to sell MSFT and AAPL for $35• Traders are intermediaries– Publication and subscription are decoupled – Buffett does not know who he sold to– Gates does not know who he bought from

Page 7: Publish-subscribe, Event  brokers

7

Stock exchange 2

• NYSE provides feed of stock updates– Humongous, fast

• Traders are only interested in parts of it– Need filtering

Page 8: Publish-subscribe, Event  brokers

8Eugster 2003: The many faces of publish/subscribe

Page 9: Publish-subscribe, Event  brokers

9

Constraints

• Subscribers register their interest– Interest in a publisher, an event, or a content

• Publishers generate events– Sometimes through intermediaries called message

broker, or message bus, or even proxy• Usually asynchronous– Publishers don’t wait for subscribers to publish– Subscribers give a callback to be notified

Page 10: Publish-subscribe, Event  brokers

10

Gains

• Scalable one-way communication– Usually over the network– “Well adapted to the loosely coupled nature of

distributed large-scale applications” [Eugster03]• Can decouple subscribers from publishers– Decoupling– Privacy

• Content filtering

Page 11: Publish-subscribe, Event  brokers

11

Request-reply vs pubsub

Request-reply• Implies client-server

– Medium coupling

• Pull info

Pubsub • Less coupled

• Push info

Page 12: Publish-subscribe, Event  brokers

12

More about pubsub

• AKA producer-consumer– Implies message queues

• Pubsub != client-server

Criteria Pubsub Client-server

Message passing One-way Two-way

Request-reply Impossible Possible

Information flow Publishers push to subscribers

Clients pull from server

Page 13: Publish-subscribe, Event  brokers

13

Pubsub + space partitioning = scale

http://www.cescg.org/CESCG-2000/JKrivanek/

Page 14: Publish-subscribe, Event  brokers

14

But …

• What if everyone subscribes to one item?– BarackObama: 43M followers on Twitter– Bandwidth limits, slower updates– Can/should cache

• What if everyone subscribes to everything?– Then Pubsub is probably not the right style

Page 15: Publish-subscribe, Event  brokers

15

Apple Push Notifications

http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

Page 16: Publish-subscribe, Event  brokers

16

Apple Push Notifications

• Subscription– Device token = content of interest– Delivered by APNS, for security – why?

• Notification– APNS intermediary between appServer and

appClient– For privacy – why?

Page 17: Publish-subscribe, Event  brokers

17

Page 18: Publish-subscribe, Event  brokers

18

Zoom-in/out

• Zoom on a region of the board– Useful with a million small pieces

• Originally client-side– The server sends all piece movement events– Most events that the client receives are not rendered,

and could be ignored• Then server-side pubsub– Only receive events near me– Client subscription == client view– Client model = subset of server model

Page 19: Publish-subscribe, Event  brokers

19

“Near me”

• Current view: x, y, w, h• Subscribe to [x: x+w, y: y+h]• Subscribe to [x-d: x+w+d, y-d: y+h+d]• Partition the world statically in cells– Subscribe to the cells that my view overlap with

User-oriented software development for real time online applications, Gorlatch 2008

Page 20: Publish-subscribe, Event  brokers

20

EVENT BROKERS

Page 21: Publish-subscribe, Event  brokers

21

Event broker vs pubsub

• Event broker = pubsub– With an intermediary – Where subscribers publish– And publishers subscribe– And usually with function callbacks rather than

over the network

Page 22: Publish-subscribe, Event  brokers

22

Mini-map

• Receive player position message• Change player position on main screen• Change player position on mini-map

Page 23: Publish-subscribe, Event  brokers

23

Page 24: Publish-subscribe, Event  brokers

24

Mini-map

• Main view and mini-map view• Both subscribe to:– My movements– Quest markers

• The main view subscribes to:– Other players movement

• The mini-map subscribes to:– Zoom clicks

Page 25: Publish-subscribe, Event  brokers

25

Widgets

• GUI widgets• N widgets interested in an event• A widget may fire another event in response– Enqueue new event?– Or dispatch it right away?

Page 26: Publish-subscribe, Event  brokers

26

Publish events

http://ezide.com/games/writing-games.html

Page 27: Publish-subscribe, Event  brokers

27

Dispatch events

http://ezide.com/games/writing-games.html

Page 28: Publish-subscribe, Event  brokers

28

If you’re interested …

• http://msdn.microsoft.com/en-us/library/ff650653.aspx

• http://ezide.com/games/writing-games.html• The Many Faces of Publish/Subscribe, Eugster

et al. 2003• http://code.google.com/p/pubsubhubbub/• http://www.capitalware.com/dl/docs/intro_p

ub_sub.pdf