Esempio n. 1
0
  public static void main(String[] args) throws Exception {
    try {
      Context context = init();
      ConnectionFactory connectionFactory =
          (ConnectionFactory) context.lookup("net4j.jms.ConnectionFactory"); // $NON-NLS-1$
      Destination destination = (Destination) context.lookup("StockTopic"); // $NON-NLS-1$

      Connection connection = connectionFactory.createConnection();
      Session session = connection.createSession(true, 0);

      MessageProducer publisher = session.createProducer(destination);
      MessageConsumer subscriber1 = session.createConsumer(destination);
      MessageConsumer subscriber2 = session.createConsumer(destination);
      subscriber1.setMessageListener(new MessageLogger("subscriber1")); // $NON-NLS-1$
      subscriber2.setMessageListener(new MessageLogger("subscriber2")); // $NON-NLS-1$

      connection.start();

      publisher.send(session.createObjectMessage("Message 1")); // $NON-NLS-1$
      publisher.send(session.createObjectMessage("Message 2")); // $NON-NLS-1$
      publisher.send(session.createObjectMessage("Message 3")); // $NON-NLS-1$
      publisher.send(session.createObjectMessage("Message 4")); // $NON-NLS-1$

      session.commit();
    } finally {
      ConcurrencyUtil.sleep(500);
      Server.INSTANCE.deactivate();
    }
  }
Esempio n. 2
0
  private static Context init() throws Exception {
    OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
    OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
    OMPlatform.INSTANCE.setDebugging(true);

    IDBAdapter.REGISTRY.put(EmbeddedDerbyAdapter.NAME, new EmbeddedDerbyAdapter());
    IStore store = JDBCUtil.getStore();
    Server.INSTANCE.setStore(store);
    Server.INSTANCE.activate();

    IManagedContainer container = new ManagedContainer();
    Net4jUtil.prepareContainer(container);
    TCPUtil.prepareContainer(container);
    JMSServerUtil.prepareContainer(container);

    TCPUtil.getAcceptor(container, null);
    IConnector connector = TCPUtil.getConnector(container, "localhost"); // $NON-NLS-1$

    IJMSAdmin admin = JMSAdminUtil.createAdmin(connector);
    admin.createQueue("StockQueue"); // $NON-NLS-1$
    admin.createTopic("StockTopic"); // $NON-NLS-1$

    return new JMSInitialContext(container);
  }