爲了本地開發和測試,咱們能夠創建一個僞集羣。僞集羣同樣包含 Pulsar broker, ZooKeeper, BookKeeper.java
生產環境
若是想運行一個完整的生產pulsar安裝, 查看http://pulsar.apache.org/docs/en/deploy-bare-metalpython
Pulsar當前能夠運行在Macos與linux系統,並且必須安裝java8.linux
經過如下方法下載二進制包git
從Apache官網的鏡像下載:github
從Pulsar官網下載頁下載 pulsar.apache.org/download/docker
從Pulsar的github發佈頁下載:https://github.com/apache/pulsar/releases/tag/v2.2.0apache
使用wget:瀏覽器
$ wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-2.2.0-bin.tar.gz
Copy複製代碼
下載完成後解壓到自定目錄:bash
$ tar xvfz apache-pulsar-2.2.0-bin.tar.gz
$ cd apache-pulsar-2.2.0
複製代碼
二進制包最初包含如下目錄:工具
Directory | Contains |
---|---|
bin |
Pulsar的命令行工具, 如 pulsar 和 pulsar-admin |
conf |
Pulsar的配置文件, 包含配置 broker configuration, ZooKeeper configuration, 等 |
examples |
一個關於Pulsar Functions的例子 |
lib |
Pulsar所依賴的一些jar包 |
licenses |
一些許可文件 |
一旦運行Pulsar,一下文件夾會被建立:
Directory | Contains |
---|---|
data |
ZooKeeper and BookKeeper 數據存儲目錄 |
instances |
Pulsar Functions 須要的目錄 |
logs |
安裝時建立的一些日誌 |
從2.1.0-incubating開始,connector單獨發佈。若是想要使用須要單獨下載。經過如下方式下載
從Apache鏡像下載:
從Pulsar 下載頁下載:http://pulsar.apache.org/download
從 Pulsar的github的發佈頁下載:https://github.com/apache/pulsar/releases/latest
使用 wget:
$ wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-io-connectors-2.2.0-bin.tar.gz
複製代碼
一旦下載完成,解壓下載的壓縮包,並把下載的東西拷貝到 pulsar 文件夾下的connectors下(若是沒有此目錄,能夠直接建立):
/pulsar
/bin
/lib
/conf
/data
/connectors
$ tar xvfz /path/to/apache-pulsar-io-connectors-2.2.0-bin.tar.gz
// you will find a directory named `apache-pulsar-io-connectors-2.2.0` in the pulsar directory
// then copy the connectors
$ cd apache-pulsar-io-connectors-2.2.0/connectors connectors
$ ls connectors
pulsar-io-aerospike-2.2.0.nar
pulsar-io-cassandra-2.2.0.nar
pulsar-io-kafka-2.2.0.nar
pulsar-io-kinesis-2.2.0.nar
pulsar-io-rabbitmq-2.2.0.nar
pulsar-io-twitter-2.2.0.nar
...
Copy複製代碼
進入咱們剛纔解壓pulsar/bin/ 文件夾下,執行以下的命令
$ bin/pulsar standalone
複製代碼
若是正常啓動會看到相似下面的信息:
2017-06-01 14:46:29,192 - INFO - [main:WebSocketService@95] - Global Zookeeper cache started
2017-06-01 14:46:29,192 - INFO - [main:AuthenticationService@61] - Authentication is disabled
2017-06-01 14:46:29,192 - INFO - [main:WebSocketService@108] - Pulsar WebSocket Service started
Copy複製代碼
咱們也能夠經過docker安裝一個pulsar的僞集羣
docker run -it -p 80:80 -p 8080:8080 -p 6650:6650 apachepulsar/pulsar-standalone
Copy複製代碼
幾個端口的做用:
啓動完成後,咱們經過瀏覽器就能夠訪問http://localhost .
Pulsar提供了一個命令行的 pulsar-client工具,下面的語句使用pulsar-client 往my-topic發送一條消息:
$ bin/pulsar-client produce my-topic --messages "hello-pulsar"複製代碼
若是發送成功,咱們會看到下面的一條消息
13:09:39.356 [main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully produced
複製代碼
不須要顯式地建立新主題
也許你注意到了,咱們發送消息以前並無事前建立my-topic。若是咱們往一個topic發送消息,若是topic事前並無建立,Pulsar會自動爲咱們建立。
集羣創建後咱們能夠經過Pulsar提供的客戶端(java, python, c ++, go 等)與 Pulsar交互了
http://localhost:8080
pulsar://localhost:6650
Java 客戶端生產者的例子:
String localClusterUrl = "pulsar://localhost:6650";
PulsarClient client = PulsarClient.builder().serviceURL(localClusterUrl).build();
Producer<byte[]> producer = client.newProducer().topic("my-topic").create();
複製代碼
Python 生產者的例子:
import pulsar
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('my-topic')
複製代碼
C++ 生產者例子:
Client client("pulsar://localhost:6650");
Producer producer;
Result result = client.createProducer("my-topic", producer);
if (result != ResultOk) {
LOG_ERROR("Error creating producer: " << result);
return -1;
}複製代碼