ActiveMQ in Action-1.4 Running your first examples with ActiveMQ- 高飞网

1.4 Running your first examples with ActiveMQ

2016-05-31 15:13:46.0

1.4 运行你的第一个ActiveMQ示例

前面已经教会你在一个终端启动ActiveMQ了。为了验证它,你现在要再开启两个终端去运行ActiveMQ示例。(译者使用的是ActiveMQ5.13.2最新版,示例与书中不一样)进入示例目录:

amqp
conf
mqtt
openwire
other
stomp

看到的是不同协议的示例,我们进入mqtt协议,其中有两个文件夹,一个是java,一个是websocket,我们进入java目录,显示如下:

pom.xml readme.md src

由上可见,这里使用的是maven构建的:

mvn clean install

然后两个终端分别运行:

java -cp target/mqtt-example-0.1-SNAPSHOT.jar example.Listener

java -cp target/mqtt-example-0.1-SNAPSHOT.jar example.Publisher

两个终端分别会打印

-----------------------------------Listener------------------------------------
Received 0 messages.
Received 1000 messages.
Received 2000 messages.
Received 3000 messages.
Received 4000 messages.
Received 5000 messages.
Received 6000 messages.
Received 7000 messages.
Received 8000 messages.
Received 9000 messages.
Received 10000 in 3.39 seconds
-------------------------------------Publisher-------------------------------------
Sent 1000 messages.
Sent 2000 messages.
Sent 3000 messages.
Sent 4000 messages.
Sent 5000 messages.
Sent 6000 messages.
Sent 7000 messages.
Sent 8000 messages.
Sent 9000 messages.
Sent 10000 messages.