Skip to content

Instantly share code, notes, and snippets.

@AndrejGajdos
Created January 16, 2016 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrejGajdos/f1589630edd3f783bc4e to your computer and use it in GitHub Desktop.
Save AndrejGajdos/f1589630edd3f783bc4e to your computer and use it in GitHub Desktop.
ActiveMQ Broker
package activemq.test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.apache.activemq.api.core.TransportConfiguration;
import org.apache.activemq.core.config.Configuration;
import org.apache.activemq.core.config.impl.ConfigurationImpl;
import org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory;
import org.apache.activemq.core.server.ActiveMQServer;
import org.apache.activemq.core.server.ActiveMQServers;
public class Server {
public static void main(final String arg[]) throws Exception {
try {
// Step 1. Create the Configuration, and set the properties
// accordingly
Configuration configuration = new ConfigurationImpl();
// we only need this for the server lock file
configuration.setJournalDirectory("target/data/journal");
configuration.setPersistenceEnabled(false); // http://activemq.apache.org/what-is-the-difference-between-persistent-and-non-persistent-delivery.html
configuration.setSecurityEnabled(false); // http://activemq.apache.org/security.html
/**
* this map with configuration values is not necessary (it
* configures the default values). If you want to modify it to run
* the example in two different hosts, remember to also modify the
* client's Connector at {@link EmbeddedRemoteExample}.
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put("host", "localhost");
map.put("port", 61616);
// https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/HornetQ_User_Guide/ch14s04.html
TransportConfiguration transpConf = new TransportConfiguration(
NettyAcceptorFactory.class.getName(), map);
HashSet<TransportConfiguration> setTransp = new HashSet<TransportConfiguration>();
setTransp.add(transpConf);
configuration.setAcceptorConfigurations(setTransp); // https://github.com/apache/activemq-6/blob/master/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/Acceptor.java
// Step 2. Create and start the server
ActiveMQServer server = ActiveMQServers
.newActiveMQServer(configuration);
server.start();
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment