Guest User

Untitled

a guest
May 6th, 2015
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.HashSet;
  3. import java.util.Map;
  4.  
  5. import org.apache.activemq.api.core.TransportConfiguration;
  6. import org.apache.activemq.core.config.Configuration;
  7. import org.apache.activemq.core.config.impl.ConfigurationImpl;
  8. import org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory;
  9. import org.apache.activemq.core.server.ActiveMQServer;
  10. import org.apache.activemq.core.server.ActiveMQServers;
  11.  
  12. public class Server {
  13.     public static void main(final String arg[]) throws Exception
  14.     {
  15.         try
  16.         {
  17.             // Step 1. Create the Configuration, and set the properties accordingly
  18.             Configuration configuration = new ConfigurationImpl();
  19.             //we only need this for the server lock file
  20.             configuration.setJournalDirectory("target/data/journal");
  21.             configuration.setPersistenceEnabled(false); // http://activemq.apache.org/what-is-the-difference-between-persistent-and-non-persistent-delivery.html
  22.             configuration.setSecurityEnabled(false); // http://activemq.apache.org/security.html
  23.             /**
  24.              * this map with configuration values is not necessary (it configures the default values).
  25.              * If you want to modify it to run the example in two different hosts, remember to also
  26.              * modify the client's Connector at {@link EmbeddedRemoteExample}.
  27.              */
  28.             Map<String, Object> map = new HashMap<String, Object>();
  29.             map.put("host", "localhost");
  30.             map.put("port", 61616);
  31.  
  32.             // https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/5/html/HornetQ_User_Guide/ch14s04.html
  33.             TransportConfiguration transpConf = new TransportConfiguration(NettyAcceptorFactory.class.getName(),map);
  34.  
  35.             HashSet<TransportConfiguration> setTransp = new HashSet<TransportConfiguration>();
  36.             setTransp.add(transpConf);
  37.  
  38.             configuration.setAcceptorConfigurations(setTransp); // https://github.com/apache/activemq-6/blob/master/activemq-server/src/main/java/org/apache/activemq/spi/core/remoting/Acceptor.java
  39.  
  40.             // Step 2. Create and start the server
  41.             ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration);
  42.             server.start();
  43.         }
  44.         catch (Exception e)
  45.         {
  46.             e.printStackTrace();
  47.             throw e;
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment