Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django, Channels, and Distributed Systems

Django, Channels, and Distributed Systems

A talk I gave at PyBay 2016

Andrew Godwin

August 21, 2016
Tweet

More Decks by Andrew Godwin

Other Decks in Programming

Transcript

  1. ???

  2. At most once / At least once Ordered / Unordered

    FIFO / FILO Expiry / Persistence
  3. Server Server Django Script ASGI "Send to channel X" "Receive

    from channel X" "Send to group Y" "Add channel X to group Y" "Remove channel X from group Y"
  4. What does Channels provide? Routing Consumers Sessions Auth Helpers By

    channel, URL, etc. Standardised message handling Cross-network persistence on sockets Including HTTP cookies on WebSocket runserver, runworker, debugging info
  5. Routing from channels import route routing = [ route("websocket.connect", on_connect),

    route("websocket.receive", on_receive), route("websocket.disconnect", on_disconnect) ]
  6. Class-based from channels import route_class routing = [ route_class(ChatConsumer), ]

    from channels.generic.websockets class ChatConsumer(WebsocketConsumer): def connection_groups(self): return ["chat"] def receive(self, text): self.group_send("chat", text=text) Routing
  7. Example: SOA Services receive()-block waiting for tasks Clients use send()

    with a reply-channel to call an endpoint Servers process and send() the reply
  8. 1995 You are a desktop app 2005 You are a

    website 2015 You are a rich web/mobile app 2025 ?