org.apache.activemq.artemis.jms.server.JMSServerManager

Here are the examples of the java api class org.apache.activemq.artemis.jms.server.JMSServerManager taken from open source projects.

1. JMSConfigurationTest#testSetupJMSConfiguration()

Project: activemq-artemis
File: JMSConfigurationTest.java
@Test
public void testSetupJMSConfiguration() throws Exception {
    Context context = new InVMNamingContext();
    ActiveMQServer coreServer = new ActiveMQServerImpl(createDefaultInVMConfig());
    JMSConfiguration jmsConfiguration = new JMSConfigurationImpl();
    TransportConfiguration connectorConfig = new TransportConfiguration(InVMConnectorFactory.class.getName());
    List<TransportConfiguration> transportConfigs = new ArrayList<>();
    transportConfigs.add(connectorConfig);
    ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName(RandomUtil.randomString()).setConnectorNames(registerConnectors(coreServer, transportConfigs)).setBindings("/cf/binding1", "/cf/binding2");
    jmsConfiguration.getConnectionFactoryConfigurations().add(cfConfig);
    JMSQueueConfigurationImpl queueConfig = new JMSQueueConfigurationImpl().setName(RandomUtil.randomString()).setDurable(false).setBindings("/queue/binding1", "/queue/binding2");
    jmsConfiguration.getQueueConfigurations().add(queueConfig);
    TopicConfiguration topicConfig = new TopicConfigurationImpl().setName(RandomUtil.randomString()).setBindings("/topic/binding1", "/topic/binding2");
    jmsConfiguration.getTopicConfigurations().add(topicConfig);
    JMSServerManager server = new JMSServerManagerImpl(coreServer, jmsConfiguration);
    server.setRegistry(new JndiBindingRegistry(context));
    server.start();
    for (String binding : cfConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof ConnectionFactory);
        ConnectionFactory cf = (ConnectionFactory) o;
        Connection connection = cf.createConnection();
        connection.close();
    }
    for (String binding : queueConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Queue);
        Queue queue = (Queue) o;
        Assert.assertEquals(queueConfig.getName(), queue.getQueueName());
    }
    for (String binding : topicConfig.getBindings()) {
        Object o = context.lookup(binding);
        Assert.assertNotNull(o);
        Assert.assertTrue(o instanceof Topic);
        Topic topic = (Topic) o;
        Assert.assertEquals(topicConfig.getName(), topic.getTopicName());
    }
    server.stop();
}

2. EmbeddedExample#main()

Project: activemq-artemis
File: EmbeddedExample.java
public static void main(final String[] args) throws Exception {
    EmbeddedJMS jmsServer = new EmbeddedJMS();
    SecurityConfiguration securityConfig = new SecurityConfiguration();
    securityConfig.addUser("guest", "guest");
    securityConfig.addRole("guest", "guest");
    securityConfig.setDefaultUser("guest");
    ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig);
    jmsServer.setSecurityManager(securityManager);
    jmsServer.start();
    System.out.println("Started Embedded JMS Server");
    JMSServerManager jmsServerManager = jmsServer.getJMSServerManager();
    List<String> connectors = new ArrayList<>();
    connectors.add("in-vm");
    jmsServerManager.createConnectionFactory("ConnectionFactory", false, JMSFactoryType.CF, connectors, "ConnectionFactory");
    jmsServerManager.createQueue(false, "exampleQueue", null, false, "queue/exampleQueue");
    ConnectionFactory cf = (ConnectionFactory) jmsServer.lookup("ConnectionFactory");
    Queue queue = (Queue) jmsServer.lookup("queue/exampleQueue");
    // Step 10. Send and receive a message using JMS API
    try (Connection connection = cf.createConnection()) {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("Hello sent at " + new Date());
        System.out.println("Sending message: " + message.getText());
        producer.send(message);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        connection.start();
        TextMessage messageReceived = (TextMessage) messageConsumer.receive(1000);
        System.out.println("Received message:" + messageReceived.getText());
    } finally {
        // Step 11. Stop the JMS server
        jmsServer.stop();
        System.out.println("Stopped the JMS Server");
    }
}

3. StompConnectionCleanupTest#createServer()

Project: activemq-artemis
File: StompConnectionCleanupTest.java
@Override
protected JMSServerManager createServer() throws Exception {
    JMSServerManager s = super.createServer();
    s.getActiveMQServer().getConfiguration().setConnectionTTLOverride(CONNECTION_TTL);
    return s;
}

4. BridgeTestBase#createQueue()

Project: activemq-artemis
File: BridgeTestBase.java
protected void createQueue(final String queueName, final int index) throws Exception {
    JMSServerManager server = jmsServer0;
    if (index == 1) {
        server = jmsServer1;
    }
    assertTrue("queue '/queue/" + queueName + "' created", server.createQueue(false, queueName, null, true, "/queue/" + queueName));
}