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. 4.

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

    Engineer Working for Hatena, Inc. Media Artist To be popular with girls...
  2. 5.

    Perl Emacs Kyoto Momoclo Architecture Jazz Sake Chinese Tea Utsuwa

    Cooking Arduino Gastronomade Nabokov Media Art Girls
  3. 13.

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

    interaction • Notification Center
  4. 14.
  5. 17.

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

    (Client App)register it to Provider
  6. 18.

    1. Provider sends notification with token 2. APNs verifies it

    and push notification to Device 3. Client App handles it
  7. 20.

    What you must implement: Client App Retrieves and register device

    token Provider Sends notification using the token
  8. 23.
  9. 31.
  10. 32.

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

    4. Daemon (apnsd) 5. APNs 6. iPhone
  11. 34.

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

    4. Daemon (apnsd) 5. APNs 6. iPhone
  12. 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
  13. 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
  14. 38.
  15. 39.

    • Device Token • JSON-formatted Hash • aps (reserved) •

    alert / badge / sound • arbitrary keys
  16. 40.

    { aps => { alert => 'Something occurred!', badge =>

    1, sound => 'notification.wav', }, type => 'comment', foo => 'bar' }
  17. 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
  18. 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
  19. 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
  20. 45.

    • Notification cooperating with Web service • Scalable and stable

    system architecture • Combination of existing modules • Hold connections and make them persistent Recap