8、Qpid
1、安装
1) 安装环境
broker安装环境:centos7 (需安装了JDK)
client测试环境:windows
2) 下载broker和client
下载地址:http://qpid.apache.org/download.html
broker版本:qpid-broker-0.32-bin.tar.gz
client版本:apache-qpid-jms-0.1.0-src.tar.gz
3) 安装broker
① 解压broker安装包
[root@localhost /]# tar -zxvf /home/download/qpid-broker-0.32-bin.tar.gz -C /opt
② 配置环境变量
[root@localhost /]# vi /etc/profile
在文件最后加入如下变量
export QPID_HOME=/opt/qpid-broker/0.32
export QPID_WORK=/var/qpidwork
然后保存退出
:wq
③ 启动qpid broker
进入qpid-broker安装目录下的bin目录启动
[root@localhost ~]# cd /opt/qpid-broker/0.32/bin/
[root@localhost bin]# ./qpid-server
启动成功如下:
./qpid-server: line 54: /var/qpidwork/qpid-server.pid: No such file or directory
System Properties set to -Damqj.logging.level=info -DQPID_HOME=/opt/qpid-broker/0.32 -DQPID_WORK=/var/qpidwork
QPID_OPTS set to -Damqj.read_write_pool_size=32 -DQPID_LOG_APPEND=
Using QPID_CLASSPATH /opt/qpid-broker/0.32/lib/*:/opt/qpid-broker/0.32/lib/plugins/*:/opt/qpid-broker/0.32/lib/opt/*
Info: QPID_JAVA_GC not set. Defaulting to JAVA_GC -XX:+UseConcMarkSweepGC -XX:+HeapDumpOnOutOfMemoryError
Info: QPID_JAVA_MEM not set. Defaulting to JAVA_MEM -Xmx2g
[Broker] BRK-1006 : Using configuration : /var/qpidwork/config.json
[Broker] BRK-1007 : Using logging configuration : /opt/qpid-broker/0.32/etc/log4j.xml
[Broker] BRK-1001 : Startup : Version: 0.32 Build: Unversioned directory
[Broker] BRK-1010 : Platform : JVM : Oracle Corporation version: 1.7.0_75-b13 OS : Linux version: 3.10.0-123.el7.x86_64 arch: amd64
[Broker] BRK-1011 : Maximum Memory : 2,138,767,360 bytes
[Broker] BRK-1017 : Process : PID : 2146
[Broker] BRK-1002 : Starting : Listening on TCP port 5672
[Broker] MNG-1001 : Web Management Startup
[Broker] MNG-1002 : Starting : HTTP : Listening on TCP port 8080
[Broker] MNG-1004 : Web Management Ready
[Broker] MNG-1001 : JMX Management Startup
[Broker] MNG-1002 : Starting : RMI Registry : Listening on TCP port 8999
[Broker] MNG-1002 : Starting : JMX RMIConnectorServer : Listening on TCP port 9099
[Broker] MNG-1004 : JMX Management Ready
[Broker] BRK-1004 : Qpid Broker Ready
④ 使用web控制台
访问地址:http://192.168.1.110:8080 进入登录界面
输入用户名和密码登录,都是为guest。
双击在virtualhosts的default菜单,如下:
添加一个名为queue的Queue
至此,broker设置完毕。下面使用官方给的客户端例子。
4) 测试官方用例
① 解压并导入官方提供的客户端项目 apache-qpid-jms-0.1.0-src.tar.gz
② 运行测试用例
5) 常见错误及解决方法
错误1:端口不正确
2015-04-29 14:00:57,889 [main ] - ERROR JmsConnectionFactory - Failed to create JMS Provider instance for: amqp
Caught exception, exiting.
javax.jms.JMSException: port out of range:-1
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:77)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:183)
at org.apache.qpid.jms.example.HelloWorld.main(HelloWorld.java:52)
Caused by: java.lang.IllegalArgumentException: port out of range:-1
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:224)
at io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:96)
at org.apache.qpid.jms.transports.netty.NettyTcpTransport.connect(NettyTcpTransport.java:118)
at org.apache.qpid.jms.provider.amqp.AmqpProvider.connect(AmqpProvider.java:152)
at org.apache.qpid.jms.JmsConnectionFactory.createProvider(JmsConnectionFactory.java:253)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:179)
... 1 more
原因是connection的URI端口不正确,默认是5672
正确示例:
amqp://192.168.1.170:5672
错误2:未找到amqp
2015-04-29 14:04:48,131 [168.1.170:5672]] - WARN AmqpAbstractResource - Open of AmqpFixedProducer { ID:RD-GaoWeiPeng-57595-1430287487525-0:1:1:1 } failed:
Caught exception, exiting.
javax.jms.InvalidDestinationException: Received error from remote peer without description [condition = amqp:not-found]
at org.apache.qpid.jms.provider.amqp.AmqpAbstractResource.getRemoteError(AmqpAbstractResource.java:243)
at org.apache.qpid.jms.provider.amqp.AmqpAbstractResource.processRemoteClose(AmqpAbstractResource.java:295)
at org.apache.qpid.jms.provider.amqp.AmqpProvider.processUpdates(AmqpProvider.java:739)
at org.apache.qpid.jms.provider.amqp.AmqpProvider.access$14(AmqpProvider.java:710)
at org.apache.qpid.jms.provider.amqp.AmqpProvider$16.run(AmqpProvider.java:655)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
原因是可能是未创建队列,请先创建队列,名称与jndi.properties中指定的队列名相同。
错误3:链接被拒绝
2015-04-29 14:06:27,354 [main ] - ERROR JmsConnectionFactory - Failed to create JMS Provider instance for: amqp
Caught exception, exiting.
javax.jms.JMSException: Connection refused: no further information: /192.168.1.170:5672
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:77)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:183)
at org.apache.qpid.jms.example.HelloWorld.main(HelloWorld.java:52)
Caused by: java.net.ConnectException: Connection refused: no further information: /192.168.1.170:5672
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:191)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:279)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:461)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:745)
原因可能是broker未启动或者connection的URI不正确
错误4:链接超时
2015-04-29 14:19:15,380 [main ] - ERROR JmsConnectionFactory - Failed to create JMS Provider instance for: amqp
Caught exception, exiting.
javax.jms.JMSException: Connection timed out: no further information: /192.168.1.17:56
at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:77)
at org.apache.qpid.jms.JmsConnectionFactory.createConnection(JmsConnectionFactory.java:183)
at org.apache.qpid.jms.example.HelloWorld.main(HelloWorld.java:52)
Caused by: java.net.ConnectException: Connection timed out: no further information: /192.168.1.17:56
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:191)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:279)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:461)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:378)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:350)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:745)
原因可能是connetion的URI指定的服务器地址不正确