Microblogging via XMPP (japanese)

Preview:

Citation preview

XMPPでMicrobloggingReal Time Web

自己紹介

• 名前: ストヤン ジェコフ

• 3人の男の子のパパ

• 職業: Software Engineer

• Contact: xmpp: //zh@jabber.jp

今日の予定• XMPP (Jabber)

• Microblogging

• XMPPでMicroblogging

• 私のプログラム - xmpp4r, ramaze, sequel

• 質問タイム

なぜ?

• Web 3.0 ? - Real Time Web?

• RSSでは不十分 (SUP)

• XMPP (Jabber)

• Webhooks

XMPP (Jabber)

London-Calcutta間の通信時間(Peter Saint-Andre)

• 1800: 2 年 (帆船)

• 1914: 1 月 (蒸気船)

• 1950: 1 週間 (airmail)

• 1980: 2 日 (overnight mail)

• 1994: 10 分 (email)

• 1999: 1 秒 (IM)

XMPPの歴史

• 1998: Jeremie Miller - ICQ - AIM (perl)

• 1999: First release

• 2001: Jabber Software Fondation

• 2004: XMPP RFCs (IETF)

XMPPって何?

• JID: node@server/Resource

• オープンプロトコル

• 分散されたサーバー

• RFC 3290 (core), 3291 (messaging)

• XMPP extension protocols (XEP)

XMPPって何? (2)

• 二方向, ストリーミング XML

• One first level tag: <stream>

• 3 second level tags:

• <presence> - presence, subscribe

• <message> - asynchronous

• <iq> - synchronous

XMPPの特徴

• presence付き

• One-to-one IM (u2u, a2u, a2a)

• Groupchat

• Geolocation

• セキュリティー - SSL, TLS

非おたく専用• 50 000+ サーバー, 5千万人+ ユーザー

• ウォールストリート

• アメリカ国防省

• Cisco, Google, Apple

• NTT ?

だれでもXMPP

• Free account - jabber.jp etc.

• GTalk for domains

• 自分のサーバーにインストール:

• ejabberd (erlang) - production

• openfire (java) - 簡単インストール

Libraries

• ほとんどのOSと言語

• loudmouth (C)

• xiff (flash)

• smack (java)

• xmpp4r (ruby)

Microblogging

Microblogging

• Web 2.0

• Microbloggingって何?

• ステータス変更

• 短い語数(140文字まで)

• メディアファイルも

Big Players

• Twitter

• Jaiku

• identi.ca (laconi.ca) - OSS

• Tumblr - http://tt.zhekov.net/

• FriendFeed, Lifestream.fm

XMPPでMicroblogginghttp://www.microblog.org/

だいたい Real Time

• XMPP bots (Jaiku, Identi.ca, FriendFeed)

• GNIP - http://www.gnipcentral.com/

• RSS-to-XMPP

• http://notify.me/

• http://notifixio.us/ (WP plugin)

XMPPでMicroblogging

• Web 3.0 (Real Time Web)

• PubSub - XEP-0060

• BOSH - XEP-0124

• XEP-XXXX

• ....

ややこしすぎるわ :(

それか、俺がばか?

自分で作ろっ!

Design

• XMPP bot

• 簡単なAPI

• 簡単な web frontend

• 見本: juick.com , kwippy.com

内容

• models.rb - connection to the DB

• bot.rb - XMPP

• api.rb - service, scaling

• web.rb - browser view

Models (DB)

• “Things”

• User

• Micro

• “Relations”

• Subscribe - User-to-User

• Subscribe - User-to-Micro

• Like - User-to-Micro

Relations (Sequel)

class User < Sequel::Model(:users)

one_to_many :micros do |ds| ds.filter(:parent_id => nil) end

one_to_many :subs, :extend => UserFindOrCreate many_to_many :publishers, :class => :User, :join_table => :subs

end

Ruby XMPP Libraries

• xmpp4r - Roster, vCard etc.

• xmpp4r-simple - 簡単

• jabber4r - Thread based :(

XMPP Bot

• http://tr.im/emxmpp (nutrun.com)

• EventMachine - libevent, Deferrable

• Plugins - http://tr.im/modular

平行性EM.run do EM::PeriodicTimer.new(1) do ... EM.spawn do worker = Worker.new worker.callback {jabber.deliver(message.from, "Done")} worker.process end.notify ... endend

class Worker include EM::Deferrable

def process ... set_deferred_status :succeeded endend

プラグインその1PluginFactory.load "plugins"...def PluginFactory.load( dirname ) Dir.open( dirname ).each do |fn| next unless ( fn =~ /[.]rb$/ ) require "#{dirname}/#{fn}" endend

プラグインその2class Plugin include EM::Deferrable

def process( args = {} ) sleep(0.05) set_deferred_status :succeeded endend

プラグインその3class NickPlugin < Plugin def process(args = {}) begin ... set_deferred_status :succeeded rescue set_deferred_status :failed end endend

class NickFactory < PluginFactoryINFO=<<INFOverb: NICKauthor: Stoyan Zhekovdescription: Get or set the nickname for some userINFO def create() return NickPlugin.new() endend

簡単な API (json)

• /users - ユーザーリスト

• /user/<nick>/<secret> - ユーザー情報

• /status/<nick>/<secret> - presence

• /micros/<page>/<format> - microsのリスト

• /micro/<id>/<secret> - micro + comments

Web (Ramaze)

class MainController < Ramaze::Controller def u nick begin @user = User.find_by_user(nick) subset = @user.micros.reverse @micros, @pager = paginate(subset, :limit => PAGE) rescue Exception => e flash[:error] = "Error: #{e.to_s}" redirect :/, :status => 302 end endend

<Demo>

やりたいこと

• Commands parser - Ragel?

• OAuth or http://xmppid.net/

• TokyoCabinet

• XMPP Component - http://github.com/julien51/babylon

• Real PubSub?

まとめ• XMPP - いける!オープンプロトコル

• xmpp4r-simple - いける! 簡単だし。

• eventmachine - 使えるnetwork library

• sequel - 使えるORM

• ramaze - 使えるweb アプリ framework

質問タイム

</stream:stream>