JMX远程访问ubuntu下ActiveMq 删除队列信息

    在ubuntu下启动ActiveMq5.5.1,并配置使其可用JMX远程访问,这样配置的需求是:必须管理队列,可删除队列中指定信息。

    配置中需要注意:

   1.  在conf/activemq.xml中broker标签中添加 useJmx="true"属性;

   2.  将启动文件bin/activemq 中的配置放开

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONFIG_DIR}/jmx.password"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONFIG_DIR}/jmx.access"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"

# Set jvm jmx configuration for controlling the broker process
# You only have to configure the first four settings if you run a ibm jvm, caused by the
# fact that IBM's jvm does not support VirtualMachine.attach(PID)
# (see also com.sun.management.jmxremote.port, .jmx.password.file and .jmx.access.file )
ACTIVEMQ_SUNJMX_CONTROL="--jmxurl service:jmx:rmi:///jndi/rmi://127.0.0.1:11099/jmxrmi --jmxuser controlRole --jmxpassword abcd1234"
#ACTIVEMQ_SUNJMX_CONTROL=""

   3. 使用命令 sudo ./activemq console 启动

       会出现以下异常:Error: Password file read access must be restricted: /opt/activemq/conf/jmx.password
       原因是因为对文件没有访问权限   

       执行

       sudo  chmod 600  /opt/activemq/conf/jmx.password

       sudo  chmod 600  /opt/activemq/conf/jmx.access

       即可正常启动

   4. 在客户端使用java代码链接

       RemoteJMXBrokerFacade createConnector = new RemoteJMXBrokerFacade();
            // 填写链接属性
        System.setProperty("webconsole.jmx.url",
                    "service:jmx:rmi:///jndi/rmi://192.168.1.5:11099/jmxrmi");
        System.setProperty("webconsole.jmx.user", "admin");
        System.setProperty("webconsole.jmx.password", "activemq");

        会出现异常:

         java.lang.RuntimeException: java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
         原因   在ubuntu下host设置不正确,修改/etc/hosts文件,对应的127.0.1.1为192.168.1.5 重启activemq可正常连接

    5. 删除队列中的某个消息java代码

       String queueName="queue";   //队列名称

       String id ="";    //队列中要删除信息的id

       QueueViewMBean qvm = createConnector.getQueue(queueName);

       qvm.removeMessage(id);

 



  



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值