org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS

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

1. ArtemisEmbeddedServerConfiguration#artemisServer()

Project: spring-boot
File: ArtemisEmbeddedServerConfiguration.java
@Bean(initMethod = "start", destroyMethod = "stop")
@ConditionalOnMissingBean
public EmbeddedJMS artemisServer(org.apache.activemq.artemis.core.config.Configuration configuration, JMSConfiguration jmsConfiguration) {
    EmbeddedJMS server = new EmbeddedJMS();
    customize(configuration);
    server.setConfiguration(configuration);
    server.setJmsConfiguration(jmsConfiguration);
    server.setRegistry(new ArtemisNoOpBindingRegistry());
    return server;
}

2. HornetQProtocolManagerTest#setUp()

Project: activemq-artemis
File: HornetQProtocolManagerTest.java
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Configuration configuration = createDefaultConfig(false);
    configuration.setPersistenceEnabled(false);
    configuration.getAcceptorConfigurations().clear();
    configuration.addAcceptorConfiguration("legacy", "tcp://localhost:61616?protocols=HORNETQ").addAcceptorConfiguration("corepr", "tcp://localhost:61617?protocols=CORE");
    configuration.addConnectorConfiguration("legacy", "tcp://localhost:61616");
    JMSConfiguration jmsConfiguration = new JMSConfigurationImpl();
    jmsConfiguration.getQueueConfigurations().add(new JMSQueueConfigurationImpl().setName("testQueue").setBindings("testQueue"));
    embeddedJMS = new EmbeddedJMS();
    embeddedJMS.setConfiguration(configuration);
    embeddedJMS.setJmsConfiguration(jmsConfiguration);
    embeddedJMS.start();
}

3. ActiveMQBootstrapListener#contextInitialized()

Project: activemq-artemis
File: ActiveMQBootstrapListener.java
@Override
public void contextInitialized(ServletContextEvent contextEvent) {
    ServletContext context = contextEvent.getServletContext();
    jms = new EmbeddedJMS();
    jms.setRegistry(new ServletContextBindingRegistry(context));
    try {
        jms.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

4. 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");
    }
}

5. FailoverTransportBrokerTest#testPublisherFailsOver()

Project: activemq-artemis
File: FailoverTransportBrokerTest.java
@Test
public void testPublisherFailsOver() throws Exception {
    // Start a normal consumer on the local broker
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.request(consumerInfo1);
    // Start a normal consumer on a remote broker
    StubConnection connection2 = createRemoteConnection();
    ConnectionInfo connectionInfo2 = createConnectionInfo();
    SessionInfo sessionInfo2 = createSessionInfo(connectionInfo2);
    ConsumerInfo consumerInfo2 = createConsumerInfo(sessionInfo2, destination);
    connection2.send(connectionInfo2);
    connection2.send(sessionInfo2);
    connection2.request(consumerInfo2);
    // Start a failover publisher.
    LOG.info("Starting the failover connection.");
    StubConnection connection3 = createFailoverConnection(null);
    ConnectionInfo connectionInfo3 = createConnectionInfo();
    SessionInfo sessionInfo3 = createSessionInfo(connectionInfo3);
    ProducerInfo producerInfo3 = createProducerInfo(sessionInfo3);
    connection3.send(connectionInfo3);
    connection3.send(sessionInfo3);
    connection3.send(producerInfo3);
    // Send the message using the fail over publisher.
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    // The message will be sent to one of the brokers.
    FailoverTransport ft = connection3.getTransport().narrow(FailoverTransport.class);
    // See which broker we were connected to.
    StubConnection connectionA;
    StubConnection connectionB;
    EmbeddedJMS serverA;
    if (new URI(newURI(0)).equals(ft.getConnectedTransportURI())) {
        connectionA = connection1;
        connectionB = connection2;
        serverA = server;
    } else {
        connectionA = connection2;
        connectionB = connection1;
        serverA = remoteServer;
    }
    Assert.assertNotNull(receiveMessage(connectionA));
    assertNoMessagesLeft(connectionB);
    // Dispose the server so that it fails over to the other server.
    LOG.info("Disconnecting the active connection");
    serverA.stop();
    connection3.request(createMessage(producerInfo3, destination, deliveryMode));
    Assert.assertNotNull(receiveMessage(connectionB));
    assertNoMessagesLeft(connectionA);
}

6. ConnectionHangOnStartupTest#createSlave()

Project: activemq-artemis
File: ConnectionHangOnStartupTest.java
protected void createSlave() throws Exception {
    Configuration config = createConfig("localhost", 1, 62002);
    EmbeddedJMS broker = new EmbeddedJMS().setConfiguration(config).setJmsConfiguration(new JMSConfigurationImpl());
    broker.start();
    slave.set(broker);
}

7. MultipleProducersPagingTest#setUp()

Project: activemq-artemis
File: MultipleProducersPagingTest.java
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE).setPageSizeBytes(50000).setMaxSizeBytes(404850);
    Configuration config = createBasicConfig().setPersistenceEnabled(false).setAddressesSettings(Collections.singletonMap("#", addressSettings)).setAcceptorConfigurations(Collections.singleton(new TransportConfiguration(NettyAcceptorFactory.class.getName()))).setConnectorConfigurations(Collections.singletonMap("netty", new TransportConfiguration(NettyConnectorFactory.class.getName())));
    final JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    jmsConfig.getConnectionFactoryConfigurations().add(new ConnectionFactoryConfigurationImpl().setName("cf").setConnectorNames(Arrays.asList("netty")).setBindings("/cf"));
    jmsConfig.getQueueConfigurations().add(new JMSQueueConfigurationImpl().setName("simple").setSelector("").setDurable(false).setBindings("/queue/simple"));
    jmsServer = new EmbeddedJMS();
    jmsServer.setConfiguration(config);
    jmsServer.setJmsConfiguration(jmsConfig);
    jmsServer.start();
    cf = (ConnectionFactory) jmsServer.lookup("/cf");
    queue = (Queue) jmsServer.lookup("/queue/simple");
    barrierLatch = new CyclicBarrier(PRODUCERS + 1);
    runnersLatch = new CountDownLatch(PRODUCERS + 1);
    msgReceived = new AtomicLong(0);
    msgSent = new AtomicLong(0);
}

8. ZeroPrefetchConsumerTest#createArtemisBroker()

Project: activemq-artemis
File: ZeroPrefetchConsumerTest.java
@Override
public EmbeddedJMS createArtemisBroker() throws Exception {
    Configuration config0 = createConfig("localhost", 0);
    String coreQueueAddress = "jms.queue." + brokerZeroQueue.getQueueName();
    AddressSettings addrSettings = new AddressSettings();
    addrSettings.setQueuePrefetch(0);
    config0.getAddressesSettings().put(coreQueueAddress, addrSettings);
    EmbeddedJMS newbroker = new EmbeddedJMS().setConfiguration(config0).setJmsConfiguration(new JMSConfigurationImpl());
    return newbroker;
}

9. FailoverRedeliveryTransactionTest#createBroker()

Project: activemq-artemis
File: FailoverRedeliveryTransactionTest.java
@Override
public EmbeddedJMS createBroker() throws Exception {
    EmbeddedJMS brokerService = super.createBroker();
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setPersistJMSRedelivered(true);
    policyMap.setDefaultEntry(defaultEntry);
    //brokerService.setDestinationPolicy(policyMap);
    return brokerService;
}

10. FailoverPriorityTest#tearDown()

Project: activemq-artemis
File: FailoverPriorityTest.java
@After
public void tearDown() throws Exception {
    shutdownClients();
    for (EmbeddedJMS server : servers) {
        if (server != null) {
            server.stop();
        }
    }
}

11. FailoverComplexClusterTest#tearDown()

Project: activemq-artemis
File: FailoverComplexClusterTest.java
@After
public void tearDown() throws Exception {
    shutdownClients();
    for (EmbeddedJMS server : servers) {
        if (server != null) {
            server.stop();
        }
    }
}

12. ConnectionHangOnStartupTest#tearDown()

Project: activemq-artemis
File: ConnectionHangOnStartupTest.java
@After
public void tearDown() throws Exception {
    EmbeddedJMS brokerService = slave.get();
    if (brokerService != null) {
        brokerService.stop();
    }
    if (master != null)
        master.stop();
}

13. AMQ1925Test#createNewServer()

Project: activemq-artemis
File: AMQ1925Test.java
private EmbeddedJMS createNewServer() throws Exception {
    Configuration config = createConfig("localhost", 0);
    EmbeddedJMS server = new EmbeddedJMS().setConfiguration(config).setJmsConfiguration(new JMSConfigurationImpl());
    return server;
}

14. EmbeddedBrokerTestSupport#createArtemisBroker()

Project: activemq-artemis
File: EmbeddedBrokerTestSupport.java
public EmbeddedJMS createArtemisBroker() throws Exception {
    Configuration config0 = createConfig("localhost", 0);
    EmbeddedJMS newbroker = new EmbeddedJMS().setConfiguration(config0).setJmsConfiguration(new JMSConfigurationImpl());
    return newbroker;
}

15. OpenwireArtemisBaseTest#createBroker()

Project: activemq-artemis
File: OpenwireArtemisBaseTest.java
public EmbeddedJMS createBroker() throws Exception {
    Configuration config0 = createConfig(0);
    EmbeddedJMS newbroker = new EmbeddedJMS().setConfiguration(config0).setJmsConfiguration(new JMSConfigurationImpl());
    return newbroker;
}

16. EmbeddedExample#main()

Project: activemq-artemis
File: EmbeddedExample.java
public static void main(final String[] args) throws Exception {
    // Step 1. Create ActiveMQ Artemis core configuration, and set the properties accordingly
    Configuration configuration = new ConfigurationImpl().setPersistenceEnabled(false).setJournalDirectory("target/data/journal").setSecurityEnabled(false).addAcceptorConfiguration(new TransportConfiguration(NettyAcceptorFactory.class.getName())).addConnectorConfiguration("connector", new TransportConfiguration(NettyConnectorFactory.class.getName()));
    // Step 2. Create the JMS configuration
    JMSConfiguration jmsConfig = new JMSConfigurationImpl();
    // Step 3. Configure the JMS ConnectionFactory
    ConnectionFactoryConfiguration cfConfig = new ConnectionFactoryConfigurationImpl().setName("cf").setConnectorNames(Arrays.asList("connector")).setBindings("cf");
    jmsConfig.getConnectionFactoryConfigurations().add(cfConfig);
    // Step 4. Configure the JMS Queue
    JMSQueueConfiguration queueConfig = new JMSQueueConfigurationImpl().setName("queue1").setDurable(false).setBindings("queue/queue1");
    jmsConfig.getQueueConfigurations().add(queueConfig);
    // Step 5. Start the JMS Server using the ActiveMQ Artemis core server and the JMS configuration
    EmbeddedJMS jmsServer = new EmbeddedJMS().setConfiguration(configuration).setJmsConfiguration(jmsConfig).start();
    System.out.println("Started Embedded JMS Server");
    // Step 6. Lookup JMS resources defined in the configuration
    ConnectionFactory cf = (ConnectionFactory) jmsServer.lookup("cf");
    Queue queue = (Queue) jmsServer.lookup("queue/queue1");
    // Step 7. Send and receive a message using JMS API
    Connection connection = null;
    try {
        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 {
        if (connection != null) {
            connection.close();
        }
        // Step 11. Stop the JMS server
        jmsServer.stop();
        System.out.println("Stopped the JMS Server");
    }
}

17. EmbeddedRestActiveMQJMS#initEmbeddedActiveMQ()

Project: activemq-artemis
File: EmbeddedRestActiveMQJMS.java
@Override
protected void initEmbeddedActiveMQ() {
    embeddedActiveMQ = new EmbeddedJMS();
}