AP4Rを試すパート2
年末年始を挟んでしまってhttp://d.hatena.ne.jp/kenmituo/20081215の続きがなかなか始められなかった。
AP4R,Rubyで非同期メッセージングを参考にしながら練習しているけど3ページ目で躓いた。
「このディレクトリ構造はどうなっているんだ?」
答えは2ページの先頭にあった。
作業ディレクトリの名前は非同期を彷彿とさせるasync_shopとしておきます。このディレクトリ以下に,Railsのルートディレクトリとしてas_rails,AP4Rのルートディレクトリとしてas_ap4rができる予定です。
つまりはこんな感じ
(参考ページも階層を書いといてくれたら悩まなくてよかったのに・・・)
Aptanaでどうやって構成しよっかな・・・
フォルダを作成して同列なプロジェクトってな感じには出来なかったのでasync_shop_as_railsという名前にしてみた。
C:\Aptana IDE Beta\async_shop>ap4r_setup as_ap4r make application root directory [C:/Aptana IDE Beta/async_shop/as_ap4r] ... make directories for AP4R [config, log, public, script, tmp] ... copy files from C:/Ruby/lib/ruby/gems/1.8/gems/ap4r-0.3.6/config to C:/Aptana ID E Beta/async_shop/as_ap4r/config ... copy files from C:/Ruby/lib/ruby/gems/1.8/gems/ap4r-0.3.6/script to C:/Aptana ID E Beta/async_shop/as_ap4r/script ... [C:/Aptana IDE Beta/async_shop/as_ap4r] has successfully set up!
これをAptana Studioのプロジェクトに組み込もうとしたらエラーになった。諦める。
% mysql -u root -p mysql> create database ap4r default character set utf8; mysql> grant all privileges on ap4r.* to ap4r@localhost identified by "ap4r"; mysql> use ap4r
そして「show databases;」ってやるとデータベースが出来ていた。
テーブルの作成
CREATE TABLE `reliable_msg_queues` ( `id` varchar(255) NOT NULL default '', `queue` varchar(255) NOT NULL default '', `headers` text NOT NULL, `object` blob NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=binary; CREATE TABLE `reliable_msg_topics` ( `topic` varchar(255) NOT NULL default '', `headers` text NOT NULL, `object` blob NOT NULL, PRIMARY KEY (`topic`) ) ENGINE=InnoDB DEFAULT CHARSET=binary;
参照ページのテーブル作成部分をコピーしてコマンドプロンプトに貼り付けた。
そしてコマンドを入れて試してみる。
% cd as_ap4r % ruby script/mongrel_ap4r start -A config/queues_mysql.cfg ** Starting AP4R Handler with config/queues_mysql.cfg Loaded queues configuration from: C:/Aptana IDE Beta/async_shop/as_ap4r/config/q ueues_mysql.cfg Using message store: mysql Accepting requests at: druby://localhost:6438 about to start dispatchers with config --- - threads: 1 targets: queue.* start dispatcher: targets= #<ReliableMsg::MultiQueue:0x5de71f0>, index= 0) dispatch targets are : queue.*; queue manager has forked dispatchers ** Signals ready. INT => stop (no restart). ** Mongrel available at 0.0.0.0:7438 ** Use CTRL-C to stop. ** Mongrel start up process completed.
動いたらしい。
% irb >> require 'rubygems' >> require 'reliable-msg' >> q = ReliableMsg::Queue.new "test" => #<ReliableMsg::Queue:0x26fdea0 @queue="test"> >> q.put "hoge" TypeError: wrong argument type UUID (expected String)
エラーがでますがな。
エラーの原因がつかめない。
だめだ・・・さっぱりわからない・・・
kiwamuさんからコメントを貰った
kiwamuさんからコメントを頂いたので試す。
C:\>gem list LOCAL GEMS (だらだらっと) uuid (2.0.1)
指摘の通りuuid-2.x.x系でした。
C:\>gem uninstall uuid You have requested to uninstall the gem: uuid-2.0.1 reliable-msg-1.1.0 depends on [uuid (>= 1.0.0)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] Y Successfully uninstalled uuid-2.0.1 C:\>gem install uuid -v 1.0.3 Successfully installed uuid-1.0.3 1 gem installed Installing ri documentation for uuid-1.0.3... Installing RDoc documentation for uuid-1.0.3...
インストール出来た。
前と同じ手順で実行してみたら・・・
irb(main):004:0> q.put "hoge" => "c71f6a91-d0ae-012b-8db2-00ff08f04386"
出来た!
kiwamuさんありがとうございます。
さて、次のステップを始めよう!