Java – Disable JMX (spring, xbean) in ActiveMQ network

Because I encountered many difficulties in this problem, I released my solution

Another problem is that this anomaly can occur even if it does not cause competitive conditions Even start a broker while waiting for them to initialize correctly between the two If a process is run by root as the first instance and another process is run as an ordinary user, the user process attempts to register its own JMX connector, even though there is already one

Or another exception that occurs when the agent that successfully registered the JMX connector closes:

These exceptions cause the broker network to stop working or not at all The trick to disabling JMX is that JMX must be disabled in case of connection failure file http://activemq.apache.org/jmx.html It does not imply a clear need to do so So I had to struggle for 2 days until I found a solution:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
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-3.0.xsd http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.3.1.xsd">

<!-- Spring JMS Template -->
<bean id="jmstemplate" class="org.springframework.jms.core.jmstemplate">
    <constructor-arg ref="connectionFactory" />
</bean>

<!-- Caching,sodass das jms template überhaupt nutzbar ist in sachen performance -->
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="amqConnectionFactory" />
    <property name="exceptionListener" ref="jmsExceptionListener" />
    <property name="sessionCacheSize" value="1" />
</bean>

<!--
    Jeder Client verbindet sich mit seinem eigenen broker,broker sind untereinander vernetzt. Nur wenn hier
    nochmals jmx deaktiviert wird,bleibt es auch deaktiviert...
-->
<amq:connectionFactory id="amqConnectionFactory" brokerURL="vm://broker:default?useJmx=false" />

<!--
    Broker suchen sich einen eigenen Port und sind gegenseitig verbunden,ergeben dadurch ein Grid. Dies zwar etwas
    langsamer,aber dafür ausfallsicherer. Siehe http://activemq.apache.org/networks-of-brokers.html
-->
<amq:broker useJmx="false" persistent="false">
    <!-- Wird benötigt um JMX endgültig zu deaktivieren -->
    <amq:managementContext>
        <amq:managementContext connectorHost="localhost" createConnector="false" />
    </amq:managementContext>
    <!-- Nun die normale Konfiguration für Network of Brokers -->
    <amq:networkConnectors>
        <amq:networkConnector networkTTL="1" duplex="true" dynamicOnly="true" uri="multicast://default" />
    </amq:networkConnectors>
    <amq:persistenceAdapter>
        <amq:memoryPersistenceAdapter />
    </amq:persistenceAdapter>
    <amq:transportConnectors>
        <amq:transportConnector uri="tcp://localhost:0" discoveryUri="multicast://default" />
    </amq:transportConnectors>
</amq:broker>

</beans>

To do this, you do not need to specify - DCOM. Com for the JVM sun. management. jmxremote = false. Neither works for me because the connectionfactory starts the JMX connector

Edit:

Tony's answer made me rethink this configuration, and I found a simplified version

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core"
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-5.3.2.xsd">

<!-- Caching,broker sind untereinander vernetzt. Nur wenn hier nochmals jmx
    deaktiviert wird,bleibt es auch deaktiviert...
-->
<amq:connectionFactory id="amqConnectionFactory" brokerURL="vm://default?broker.persistent=false" />

<!--
    Broker suchen sich einen eigenen Port und sind gegenseitig verbunden,aber dafür ausfallsicherer. Siehe http://activemq.apache.org/networks-of-brokers.html
-->
<amq:broker useJmx="false" persistent="false">
    <amq:networkConnectors>
        <amq:networkConnector networkTTL="1" conduitSubscriptions="true" duplex="true" dynamicOnly="true"
            uri="multicast://default" />
    </amq:networkConnectors>
    <amq:persistenceAdapter>
        <amq:memoryPersistenceAdapter />
    </amq:persistenceAdapter>
    <amq:transportConnectors>
        <amq:transportConnector uri="tcp://localhost:0" discoveryUri="multicast://default" />
    </amq:transportConnectors>
</amq:broker>

Solution

You can pass other parameters to the proxy URL, such as

vm://localhost?broker.persistent=false&broker.useJmx=false

broker. Usejmx = false will do tricks

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>