cherry728 寫:
如題,例如在一個map()函數中調用已經發佈的web服務,能否給我看個簡單的示例,萬分感謝
「調用」的意思是?發起一個 GET 去存取某個 RESTful 網址?
我覺得用 hadoop streaming 搭配 curl 應該就可以做到一些事情吧。
把底下的 urls 內容換成
http://your_service/?a=AAAAA&b=BBBBBBB 也就是用 curl 去做 RESTful web service 的調用。
代碼:
h998@hadoop:~$ cat urls
http://tw.yahoo.com
http://forum.hadoop.tw
h998@hadoop:~$ hadoop fs -put urls .
h998@hadoop:~$ cat mapper.sh
#!/bin/bash
while read LINE; do
curl ${LINE} # do something with it here
done
h998@hadoop:~$ chmod a+x mapper.sh
h998@hadoop:~$ hadoop jar hadoop-streaming.jar -input urls -output results -mapper mapper.sh -numReduceTasks 0 -file mapper.sh
h998@hadoop:~$ hadoop fs -lsr /user/h998/results
-rw-r--r-- 2 h998 supergroup 15952 2013-06-03 16:50 /user/h998/results/part-00000
-rw-r--r-- 2 h998 supergroup 305802 2013-06-03 16:50 /user/h998/results/part-00001
h998@hadoop:~$ hadoop fs -cat /user/h998/results/part-00000
h998@hadoop:~$ hadoop fs -cat /user/h998/results/part-00001
上面 part-00000 跟 part-00001 分別是 forum.hadoop.tw 跟 tw.yahoo.com 的 HTML 原始碼。
- Jazz