Groovy ActiveMQ 5.8嵌入式代理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Groovy ActiveMQ 5.8嵌入式代理相关的知识,希望对你有一定的参考价值。
ActiveMQ 5.8 Groovy Embeded Broker Example - Laurence Toenjes - 5/14/2013This example overcomes some limitations of the basic ActiveMQ embedded
brokers examples I found online
Some of the challenges were:
# Multiple instances on same machine and be able to use JMX.
# Running on a machine with less than 50G or 100G disk space
caused combinations of ActiveMQ errors or warnings.
# Groovy Grapes/Grab syntax to use that would work on pc and mac.
The broker in this example uses a nonpersistent store and
is multicast discoverable and should allow you to run multiple instances
of it (in separate processes of course) which is the reason for all the
code snips containing random port nums and random thread sleeps
to increase the odds of success of each new embedded broker process
to get a working set of port nums.
#!/usr/bin/env groovy @Grapes([ ]) // file: EmbeddedBroker.groovy /* ActiveMQ 5.8 Groovy Embeded Broker Example - Laurence Toenjes - 5/14/2013 This example overcomes some limitations of the basic ActiveMQ embedded brokers examples I found online Some of the challenges were: # Multiple instances on same machine and be able to use JMX. # Running on a machine with less than 50G or 100G disk space caused combinations of ActiveMQ errors or warnings. # Groovy Grapes/Grab syntax to use that would work on pc and mac. The broker in this example uses a nonpersistent store and is multicast discoverable and should allow you to run multiple instances of it (in separate processes of course) which is the reason for all the code snips containing random port nums and random thread sleeps to increase the odds of success of each new embedded broker process to get a working set of port nums. */ // /* SET _JAVA_OPTIONS=-Dcom.sun.management.jmxremote ^ -Dcom.sun.management.jmxremote.port=51001 ^ -Dcom.sun.management.jmxremote.local.only=false ^ -Dcom.sun.management.jmxremote.authenticate=false ^ -DmyJmxConnectorPort=41001 */ sockets = []; ports = []; // lets make activemq port same as pid so easy to use jconsole ports[-1] = javaPid ports; // return } calcPorts(); try { // sockets = ports.collect { new Socket(it) } } } sockets.clear(); calcPorts(); } } sm.'com.sun.management.jmxremote.port' = ports[0].toString() sm.'com.sun.management.jmxremote.local.only' = 'false' sm.'com.sun.management.jmxremote.authenticate' = 'false' sm.'myJmxConnectorPort' = ports[1].toString() // ports[0] is for com.sun.management.jmxremote.port // ports[1] is for broker.getManagementContext().setConnectorPort BrokerService broker tryCounter = 100; try { broker = createBroker(); // run forever lock.wait(); } println "### Oops: ${ex}" } } // end while } // Stop ActiveMQ 5.8 Errors or Warnings when running on machines with // less than 50G to 100G of diskspace Long HundredGig = 107374182400L } broker.systemUsage.tempUsage.limit = fileVisitor.usableSpace/2; broker.systemUsage.storeUsage.limit = fileVisitor.usableSpace/2; } // String theBrokerSuffix = sJavaPid.replace('@','_'); broker.brokerName = 'broker1' // sometimes set in bat/sh starter broker.getManagementContext().setConnectorPort( myJmxConnectorPort ); // !!! for jmx usage broker.setBrokerObjectName( BrokerMBeanSupport.createBrokerObjectName(broker.getManagementContext().getJmxDomainName(), broker.brokerName) ) def conn = broker.addConnector("tcp://0.0.0.0:${calcMqPort()}"); // use 0.0.0.0 , makes discovery work better // conn.name += "_port_${javaPid}" // for discovery conn.discoveryUri = new URI( "${C_DEFAULT_DISCOVERY_URI_STRING}?useLocalHost=false".trim() ); // optional add ? } }
以上是关于Groovy ActiveMQ 5.8嵌入式代理的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Spring 嵌入式 ActiveMQ 代理指定自定义 activemq.xml?
在同一条消息中从嵌入式代理接收消息的最佳方式是啥?(ActiveMQ)