Pro Yearly is on sale from $80 to $50! »

Hatena Goes Realtime #kansaipm 14

Hatena Goes Realtime #kansaipm 14

How does Hatena do with so-called Realtime-Web, especially about Hatena::Notify and APNs.

23f4d5d797a91b6d17d627b90b5a42d9?s=128

Kentaro Kuribayashi

November 26, 2011
Tweet

Transcript

  1. Hatena Goes Realtime Kansai.pm #14 2011-11-26 (Sat.) @Hatena Kyoto

  2. Realtime Web Push Notification Hatena::Notify APNs in Hatena

  3. Kentaro Kuribayashi id:antipop @kentaro http://kentaro.hatenablog.com/

  4. PrePAN Social reviewing site for Perl Modules @YAPC::Asia 2011 Application

    Engineer Working for Hatena, Inc. Media Artist To be popular with girls...
  5. Perl Emacs Kyoto Momoclo Architecture Jazz Sake Chinese Tea Utsuwa

    Cooking Arduino Gastronomade Nabokov Media Art Girls
  6. Realtime Web

  7. Rapid Communication to be... Social Frequent Intimate More Looser

  8. Twitter Facebook Hatena Google+

  9. Laptops Smartphones Tablets

  10. Push Notification

  11. iPhone Android APNs: Apple Push Notification Service C2DM: Cloud to

    Device Messaging
  12. iPhone APNs: Apple Push Notification Service

  13. iOS4 to iOS5 • Alert → Banner • Doesn’t disturb

    interaction • Notification Center
  14. None
  15. APNs in 3 Minutes

  16. •Provider (Web Service) •APNs •Device (iPhone) •Client App (Application)

  17. 1. Device requests token 2. APNs gives it 3. Device

    (Client App)register it to Provider
  18. 1. Provider sends notification with token 2. APNs verifies it

    and push notification to Device 3. Client App handles it
  19. That’s All!

  20. What you must implement: Client App Retrieves and register device

    token Provider Sends notification using the token
  21. Hatena::Notify

  22. Hatena::Notify

  23. User adds ˒ to some entry ↓ Notification will be

    appear on “Global Header”
  24. User comments on some entry ↓ Notification will be appear

    on “Global Header”
  25. User starts following someone ↓ Notification will be appear on

    “Global Header”
  26. Notification Center Hatena::Star Hatena::Blog UgoMemo::Hatena Hatena::Bookmark Hatena::Diary etc.

  27. Applications just send notifications on each events Hatena::Notify is a

    hub of Hatena services
  28. APNs in Hatena

  29. Web Services Device +

  30. ίϨφχ Questions with Images

  31. None
  32. 1. Services 2. Notification Center 3. Job Queue + Workers

    4. Daemon (apnsd) 5. APNs 6. iPhone
  33. TheSchwartz with WorkerManager

  34. 1. Services 2. Notification Center 3. Job Queue + Workers

    4. Daemon (apnsd) 5. APNs 6. iPhone
  35. AnyEvent::MPRPC AnyEvent::APNS with daemontools

  36. use AnyEvent::MPRPC; # server my $server = mprpc_server '127.0.0.1', '4423';

    $server->reg_cb( notify => sub { my ($res_cv, $params) = @_; # ... do something ... $res_cv->result($result); }, ); # client my $client = mprpc_client '127.0.0.1', '4423'; $client->call(notify => $params)->recv; AnyEvent::MPRPC
  37. use AnyEvent::APNS; my $cv = AnyEvent->condvar; my $apns; $apns =

    AnyEvent::APNS->new( certificate => 'your apns certificate file', private_key => 'your apns private key file', on_error => sub { ... }, on_connect => sub { $apns->send($device_token => { aps => { alert => 'Message received from Bob', }, }); }, ); AnyEvent::APNS
  38. 1. Opens socket to APNs 2. Writes notification data into

    it 3. Independent binary format
  39. • Device Token • JSON-formatted Hash • aps (reserved) •

    alert / badge / sound • arbitrary keys
  40. { aps => { alert => 'Something occurred!', badge =>

    1, sound => 'notification.wav', }, type => 'comment', foo => 'bar' }
  41. To be sure to make connection persistent APNs may consider

    connections that are rapidly and repeatedly established and torn down as a denial-of-service attack. Upon error, APNs closes the connection on which the error occurred. https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/ CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW1
  42. $self->client->call(notify => { app_name => $self->app_name, device_token => pack('H*', $self-

    >device_token), payload => { aps => { alert => $message, badge => $badge, sound => $sound, }, subject => $self->subject || '', verb => $self->verb || '', }, })->recv; AnyEvent::MPRPC::Client
  43. $self->server->reg_cb( notify => sub { my ($res_cv, $params) = @_;

    $params ||= {}; my $app_name = $params->{app_name}; my $device_token = $params->{device_token}; my $payload = $params->{payload}; my $connection = $self->connection($app_name); $res_cv->result( $connection->notify($device_token, $payload) ); }, ); AnyEvent::MPRPC::Server
  44. • RPC using AE::MPRPC • Connection plooling • Some custom

    fields • subject •verb
  45. • Notification cooperating with Web service • Scalable and stable

    system architecture • Combination of existing modules • Hold connections and make them persistent Recap
  46. Any Questions?