stompserver ã® RESTful ãªã¤ã³ã¿ã¼ãã§ã¼ã¹
前回ã®ç¶ãã§ãã
stompserver ã« RESTful ãªå£ããããããªã®ã§ä»åã¯ãã¡ããè¦ã¦ã¿ã¾ãã
ã¾ãã¯ãbin/stompserver ãå¼ãã¾ãã
$HTTP_ENABLE ãtrue ã«ããã ãã§ããããã§ãhttp.rb ãèªã¿ãã¾ããHTTPãã³ãã©ãéå§ããã¾ãã
- $HTTP_ENABLE = false + $HTTP_ENABLE = true If $HTTP_ENABLE require 'mongrel' require 'stomp_server/protocols/http' end ... if $HTTP_ENABLE puts "Http protocol handler starting on #{config.opts[:host]} port 8080" EventMachine.start_server(config.opts[:host], 8080, StompServer::Protocols::Http) {|s| s.instance_eval { @@auth_required=stomp.auth_required @@queue_manager=stomp.queue_manager @@topic_manager=stomp.topic_manager @@stompauth = stomp.stompauth } } end
ã§ãstompserver ãåèµ·åãã¾ãããã
ãã¾ã HTTP ãã³ãã©ãåãã ããããã§ãã
% stompserver -p 61613 -b 0.0.0.0 -q file -s .stompfile Queue initialized in /Users/kiwamu/work/temp/stomp/.stompfile TopicManager initialized QueueManager initialized Stomp protocol handler starting on 0.0.0.0 port 61613 Http protocol handler starting on 0.0.0.0 port 8080
æ·±ãèããã«ãã©ã¦ã¶ãããããã¦ã¿ã¾ãã
ããã¨ããã©ã¦ã¶ã« "No messages in queue" ã¨è¡¨ç¤ºããã¾ããã
HTTP ã§ã¡ãã»ã¼ã¸ã send ããã®ã¯ãã¦ããã前回ã®æé 㧠stomp (ãããã³ã«) ã§ã¤ã£ããã§ãåæ§ã«ãã©ã¦ã¶ãã確èªãã¦ã¿ãã¨ããã¯ã "No messages in queue"...
ãã¶ããå®å
ã«è¨å®ãã¦ãããã¥ã¼ã®ååã URL ã«ãããã ãããªãã¨æãã¤ã¤ã試ãã¦ã¿ãã¨ã¡ããã¨è¿ã£ã¦ãã¾ããâª
ä»åº¦ã¯ãã©ã¦ã¶ã« "Hello, world!" ã¨è¡¨ç¤ºããã¦ãã¾ãã
ããã²ã¨ã¤ã¡ãã»ã¼ã¸ã send ãã¦ããä¸ã® URL ããããã¦ã¿ãã¨ããã¯ã "Hello, world!" ã¨ã ã表示ããã¾ãã
HTTP GET ãããã³ã«ã¡ãã»ã¼ã¸ãæ¶è²»ãã¦ããããã§ããã
ã¡ãã»ã¼ã¸ãæ°ãã send ããã«ããä¸åº¦ URL ããããã¨ã"No messages in queue" ã¨ãªãã¾ããã
ããã¾ã§ãã¦ãµã¨...ãããããã©ã¦ã¶åããã¾ã§ããªãã£ãããã¨... (^^;
% irb >> require 'net/http' => [] >> Net::HTTP.version_1_2 => true >> Net::HTTP.start('localhost', 8080) {|http| ?> response = http.get('/queue/test') >> puts response.body >> } No messages in queue => nil
ã§ã¯ãHTTP ã§ã¡ãã»ã¼ã¸ã send ãã¦ã¿ã¾ãã
% irb >> require 'net/http' => [] >> Net::HTTP.version_1_2 => true >> Net::HTTP.start('localhost', 8080) {|http| ?> response = http.post('/queue/test', 'Hello, world! from HTTP') >> } => #<Net::HTTPInternalServerError 500 Server Error readbody=true>
ããã...500 çªãè¿ã£ã¦ãã¾ãã?
stompserver/protocols/http.rb ããªããã¦ã¿ãã¨ãHTTP POST ã§ã¯ãªã PUT ãåãã¤ããããã«ãªã£ã¦ãã¾ããã¤ã¾ããã¡ãã»ã¼ã¸ã send ããã«ã¯ HTTP PUT ã§æããå¿
è¦ãããã¨ã®ãã¨ãWeb ãªã½ã¼ã¹ã® CRUD ã£ã¦ C 㯠POST ãããªãã£ãã§ããã£ã? ã???
ä¸æ¬æãªãã HTTP PUT ãã¦ã¿ãã¨ãã¡ããã¨ã¡ãã»ã¼ã¸ããã¥ã¼ã«ã¯ããã¾ããã
>> Net::HTTP.start('localhost', 8080) {|http| ?> response = http.put('/queue/test', 'Hello, world! from HTTP') >> } => #<Net::HTTPOK 200 OK readbody=true>
GET ãã¦ã¿ãã¨ããããã«ã¡ãã»ã¼ã¸ãããã¾ããã
>> Net::HTTP.start('localhost', 8080) {|http| ?> response = http.get('/queue/test') >> puts response.body >> } Hello, world! from HTTP => nil
Stomp ã®ãããã¼é¨ã«è¼ãæ
å ±ã®è§£æã¯ãç¾æç¹ã§ã¯å®è£
ããã¦ããªããã®ã®ãHTTP ã ãã§ã¡ãã»ã¼ã¸ãéããã£ã¦ã®ã¯ä½¿ãã©ããã®å¹
ãåºããã¾ããã
AP4R ã§ãä»å¾ãRESTful ãªã¤ã³ã¿ã¼ãã§ã¼ã¹ãç¨æãã¦ããäºå®ã§ãã
追è¨: 2007.11.15
subscribe ããã®ã« HTTP GET ã使ã£ã¦ããç¹ãã¹ã«ã¼ãã¦ã¾ããããããã HTTP ã®ä»æ§ã¨ãã¦ã¯ããããã§ãããGET ã§ã¯ãªã½ã¼ã¹ã«å¯¾ãã¦å¯ä½ç¨ããããªãã¯ããªã®ã§ãã¡ãã»ã¼ã¸ãé²è¦§ããã ããªãã¨ããããæ¶è²»ãã¦ãã¾ãã®ã¯ã¾ããã§ãã
ã¡ãã£ã¨åã« ActiveMQ ã® REST 対å¿ã§ããä¼¼ããããªè©±é¡ã Paul Winkler ããããææããã¦ã¾ããã
- rest-discuss : Message queues
http://tech.groups.yahoo.com/group/rest-discuss/message/8955
it's not REST that says GET is a read-only operation; it's HTTP. So
their HTTP implementation is broken. Sadly seems to be pretty common.
DELETE on a URL representing a queue means you want to delete the
entire queue, not a single message!
ãã®çµæãActiveMQ ã® REST 対å¿ã®ä»æ§ããããªæãã«å¤åãã¦ããã£ã½ãã§ãããããã«ãä¸ã®ææãåãã¦å¤ãã£ã¦ãã¦ãã¾ãã
http://activemq.apache.org/rest-protocols.html