xiangzhitong 2016-03-11 07:35 采纳率: 0%
浏览 2510
已结题

【防火墙已关闭】帮看下JMX本地Main方法连接取Broker报错

**帮我看下JMX本地Main方法连接取Broker报错

(No broker is found at any of the 1 configured urls)**

JConsole通过jmxrmi连接
service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi本地正常

JConsole本地连接截图

activemq.xml配置

 <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!-- START SNIPPET: example -->
<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

   <!-- Allows accessing the server log -->
    <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
          lazy-init="false" scope="singleton"
          init-method="start" destroy-method="stop">
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="wwwwww" dataDirectory="${activemq.data}" useJmx="true">

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" >
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                         http://activemq.apache.org/slow-consumer-handling.html

                    -->
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
                </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>


        <!--
            The managementContext is used to configure how ActiveMQ is exposed in
            JMX. By default, ActiveMQ uses the MBean server that is started by
            the JVM. For more information, see:

            http://activemq.apache.org/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="true"/>
        </managementContext>

        <!--
            Configure message persistence for the broker. The default persistence
            mechanism is the KahaDB store (identified by the kahaDB tag).
            For more information, see:

            http://activemq.apache.org/persistence.html
            <kahaDB directory="${activemq.data}/kahadb"/>
        -->
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
            <!--<jdbcPersistenceAdapter dataDirectory="${activemq.data}" dataSource="#derby-ds"/>
            <jdbcPersistenceAdapter dataSource="#mysql-ds" createTablesOnStartup="true" />-->
        </persistenceAdapter>


          <!--
            The systemUsage controls the maximum amount of space the broker will
            use before disabling caching and/or slowing down producers. For more information, see:
            http://activemq.apache.org/producer-flow-control.html
          -->
          <systemUsage>
            <systemUsage>
                <memoryUsage>
                    <memoryUsage percentOfJvmHeap="70" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!--
            The transport connectors expose ActiveMQ over a given protocol to
            clients and other brokers. For more information, see:

            http://activemq.apache.org/configuring-transports.html
        -->
        <transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
            <transportConnector name="openwire" uri="tcp://127.0.0.1:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>

        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

        <plugins>
        <simpleAuthenticationPlugin>
            <users>
                <authenticationUser username="user" password="user123" groups="users" />
            </users>
        </simpleAuthenticationPlugin>
    </plugins>

    </broker>

     <!--<bean id="derby-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://10.0.10.66/activemq?relaxAutoCommit=true"/>
        <property name="username" value="root"/>
        <property name="password" value="123456"/>
        <property name="maxTotal" value="200"/>
        <property name="poolPreparedStatements" value="true"/>
     </bean>


        Enable web consoles, REST and Ajax APIs and demos
        The web consoles requires by default login, you can disable this in the jetty.xml file

        Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
    -->
    <import resource="jetty.xml"/>

</beans>
<!-- END SNIPPET: example -->

main方法报错 -----No broker is found at any of the 1 configured urls

 String ip = "127.0.0.1";
            RemoteJMXBrokerFacade createConnector = new RemoteJMXBrokerFacade(); 
            System.out.println("service:jmx:rmi:///jndi/rmi://"+ip+":1099/jmxrmi");
            System.setProperty("webconsole.jmx.url", "service:jmx:rmi:///jndi/rmi://"+ip+":1099/jmxrmi"); 
            System.setProperty("webconsole.jmx.user","admin"); 
            System.setProperty("webconsole.jmx.password","activemq"); 
            SystemPropertiesConfiguration configuration = new SystemPropertiesConfiguration(); 
            createConnector.setConfiguration(configuration); 
            System.out.println(configuration);
            System.out.println(ip+"执行开始-------"+configuration.getJmxUser());
            try { 
                BrokerViewMBean brokerAdmin = createConnector.getBrokerAdmin(); 
                String brokerName =brokerAdmin.getBrokerName();
                System.out.println("BrokerName ="+brokerName );
                long messages =brokerAdmin.getTotalMessageCount();
                System.out.println("messages ="+messages );
                long consumerCount=brokerAdmin.getTotalConsumerCount();
                System.out.println("consumerCount ="+consumerCount );
                long dequeueCount=brokerAdmin.getTotalDequeueCount();
                System.out.println("dequeueCount ="+dequeueCount );
                long enqueueCount=brokerAdmin.getTotalEnqueueCount();
                System.out.println("enqueueCount ="+enqueueCount );

                System.out.println(brokerAdmin.getBrokerName()); 
                //获取Topic相关的ObjectName
                ObjectName[] topicList=brokerAdmin.getTopics();
                System.out.println("topic ="+topicList.length);
                //获取Queue相关的ObjectName
                ObjectName[] queueList=brokerAdmin.getQueues();
                System.out.println("queue ="+queueList.length);
                //根据ObjectName创建相关的JMX对象获取相关的信息。
            } catch (Exception e) { 
                e.printStackTrace(); 
            } 
            System.out.println(ip+"执行结束-------");
    }

Console 信息

 service:jmx:rmi:///jndi/rmi://127.0.0.1:1099/jmxrmi
org.apache.activemq.web.config.SystemPropertiesConfiguration@4fccd51b
127.0.0.1执行开始-------admin
15:34:03.993 [main] DEBUG o.a.a.web.RemoteJMXBrokerFacade - Creating a new JMX-Connection to the broker
15:34:04.017 [main] DEBUG org.eclipse.jetty.util.log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog
15:34:04.022 [main] INFO  org.eclipse.jetty.util.log - Logging initialized @283ms
15:34:04.023 [main] DEBUG jndi - InitialContextFactory.getInitialContext()
15:34:04.027 [main] DEBUG jndi - supportDeepBinding=false
15:34:04.027 [main] DEBUG jndi - Created initial context delegate for local namespace:org.eclipse.jetty.jndi.local.localContextRoot@233c0b17
java.lang.IllegalStateException: No broker is found at any of the 1 configured urls
    at org.apache.activemq.web.RemoteJMXBrokerFacade.createConnection(RemoteJMXBrokerFacade.java:168)
    at org.apache.activemq.web.RemoteJMXBrokerFacade.getMBeanServerConnection(RemoteJMXBrokerFacade.java:114)
    at org.apache.activemq.web.RemoteJMXBrokerFacade.getBrokerAdmin(RemoteJMXBrokerFacade.java:88)
    at com.generateid.ActiveMQJMX.main(ActiveMQJMX.java:45)
127.0.0.1执行结束-------
  • 写回答

2条回答 默认 最新

  • kiansoung 2016-03-11 07:52
    关注
    1. ActiveMQ没有启动或启动失败
    2. ActiveMQ的连接方式错误!
    3. 连接的地址错误
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试