Advertisement
Guest User

EmbeddedServer

a guest
Mar 31st, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. public class EmbeddedServer {
  2.  
  3.     public static void main(final String arg[]) throws Exception {
  4.         try {
  5.             // Step 1. Create the Configuration, and set the properties accordingly
  6.             Configuration configuration = new ConfigurationImpl();
  7.             //we only need this for the server lock file
  8.             configuration.setJournalDirectory("target/data/journal");
  9.             configuration.setPersistenceEnabled(false);
  10.             configuration.setSecurityEnabled(false);
  11.             /**
  12.              * this map with configuration values is not necessary (it configures the default values).
  13.              * If you want to modify it to run the example in two different hosts, remember to also
  14.              * modify the client's Connector at {@link EmbeddedRemoteExample}.
  15.              */
  16.             Map<String, Object> map = new HashMap<String, Object>();
  17.             map.put("host", "localhost");
  18.             map.put("port", 5445);
  19.  
  20.             TransportConfiguration transpConf = new TransportConfiguration(NettyAcceptorFactory.class.getName(), map);
  21.  
  22.             HashSet<TransportConfiguration> setTransp = new HashSet<>();
  23.             setTransp.add(transpConf);
  24.  
  25.             configuration.setAcceptorConfigurations(setTransp);
  26.  
  27.             // Step 2. Create and start the server
  28.             HornetQServer server = HornetQServers.newHornetQServer(configuration);
  29.             server.start();
  30.  
  31.             ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), map));
  32.             ClientSessionFactory sf = serverLocator.createSessionFactory();
  33.  
  34.             // Step 4. Create a core queue
  35.             ClientSession coreSession = sf.createSession(false, false, false);
  36.  
  37.             coreSession.createQueue(Properties.queueName, Properties.queueName, true);
  38.  
  39.             coreSession.close();
  40.         } catch (Exception e) {
  41.             e.printStackTrace();
  42.             throw e;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement