use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ConfigTest method testConnectorConfig.
@Test
public void testConnectorConfig() throws Exception {
File journalFile = new File(JOURNAL_ROOT + "testMemoryConfig");
recursiveDelete(journalFile);
File derbyFile = new File(DERBY_ROOT + "testMemoryConfig");
recursiveDelete(derbyFile);
final int MAX_PRODUCERS = 5;
final int MAX_CONSUMERS = 10;
BrokerService broker = createBroker(new FileSystemResource(CONF_ROOT + "connector-properties.xml"));
broker.start();
try {
assertEquals(broker.getTransportConnectorByScheme("tcp").getMaximumProducersAllowedPerConnection(), MAX_PRODUCERS);
assertEquals(broker.getTransportConnectorByScheme("tcp").getMaximumConsumersAllowedPerConnection(), MAX_CONSUMERS);
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61631");
javax.jms.Connection connection = activeMQConnectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("test.foo");
for (int i = 0; i < MAX_PRODUCERS; i++) {
session.createProducer(topic);
}
try {
session.createProducer(topic);
fail("Should have got an exception on exceeding MAX_PRODUCERS");
} catch (JMSException expected) {
}
try {
for (int i = 0; i < (MAX_CONSUMERS + 1); i++) {
MessageConsumer consumer = session.createConsumer(topic);
assertNotNull(consumer);
}
fail("Should have caught an exception");
} catch (JMSException e) {
}
LOG.info("Success");
} finally {
broker.stop();
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class BrokerNetworkWithStuckMessagesTest method browseQueueWithJms.
@SuppressWarnings("unused")
private Object[] browseQueueWithJms(BrokerService broker) throws Exception {
Object[] messages = null;
Connection connection = null;
Session session = null;
try {
URI brokerUri = connector.getUri();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUri.toString());
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = session.createQueue(queueName);
QueueBrowser browser = session.createBrowser(destination);
List<Message> list = new ArrayList<>();
for (Enumeration<Message> enumn = browser.getEnumeration(); enumn.hasMoreElements(); ) {
list.add(enumn.nextElement());
}
messages = list.toArray();
} finally {
if (session != null) {
session.close();
}
if (connection != null) {
connection.close();
}
}
LOG.info("+Browsed with JMS: " + messages.length);
return messages;
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class NetworkConnectionsTest method testNetworkConnectionReAddURI.
@Test
public void testNetworkConnectionReAddURI() throws Exception {
LOG.info("testNetworkConnectionReAddURI is starting...");
LOG.info("Adding network connector 'NC1'...");
NetworkConnector nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
nc.setName("NC1");
nc.start();
assertTrue(nc.isStarted());
LOG.info("Looking up network connector by name...");
NetworkConnector nc1 = localBroker.getNetworkConnectorByName("NC1");
assertNotNull("Should find network connector 'NC1'", nc1);
assertTrue(nc1.isStarted());
assertEquals(nc, nc1);
LOG.info("Setting up producer and consumer...");
ActiveMQQueue destination = new ActiveMQQueue(DESTINATION_NAME);
ActiveMQConnectionFactory localFactory = new ActiveMQConnectionFactory(LOCAL_BROKER_TRANSPORT_URI);
Connection localConnection = localFactory.createConnection();
localConnection.start();
Session localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer localProducer = localSession.createProducer(destination);
ActiveMQConnectionFactory remoteFactory = new ActiveMQConnectionFactory(REMOTE_BROKER_TRANSPORT_URI);
Connection remoteConnection = remoteFactory.createConnection();
remoteConnection.start();
Session remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer remoteConsumer = remoteSession.createConsumer(destination);
Message message = localSession.createTextMessage("test");
localProducer.send(message);
LOG.info("Testing initial network connection...");
message = remoteConsumer.receive(10000);
assertNotNull(message);
LOG.info("Stopping network connector 'NC1'...");
nc.stop();
assertFalse(nc.isStarted());
LOG.info("Removing network connector...");
assertTrue(localBroker.removeNetworkConnector(nc));
nc1 = localBroker.getNetworkConnectorByName("NC1");
assertNull("Should not find network connector 'NC1'", nc1);
LOG.info("Re-adding network connector 'NC2'...");
nc = localBroker.addNetworkConnector("static:(" + REMOTE_BROKER_TRANSPORT_URI + ")");
nc.setName("NC2");
nc.start();
assertTrue(nc.isStarted());
LOG.info("Looking up network connector by name...");
NetworkConnector nc2 = localBroker.getNetworkConnectorByName("NC2");
assertNotNull(nc2);
assertTrue(nc2.isStarted());
assertEquals(nc, nc2);
LOG.info("Testing re-added network connection...");
message = localSession.createTextMessage("test");
localProducer.send(message);
message = remoteConsumer.receive(10000);
assertNotNull(message);
LOG.info("Stopping network connector...");
nc.stop();
assertFalse(nc.isStarted());
LOG.info("Removing network connection 'NC2'");
assertTrue(localBroker.removeNetworkConnector(nc));
nc2 = localBroker.getNetworkConnectorByName("NC2");
assertNull("Should not find network connector 'NC2'", nc2);
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ActiveMQAdmin method createConnectionFactory.
@Override
public void createConnectionFactory(String name) {
try {
final ConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
((ActiveMQConnectionFactory) factory).setNestedMapAndListEnabled(false);
context.bind(name, factory);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.activemq.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ConfigUsingDestinationOptionsTest method testValidSelectorConfig.
@Test(timeout = 60000)
public void testValidSelectorConfig() throws JMSException {
ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test=1");
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
Connection conn = factory.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
ActiveMQMessageConsumer cons;
// JMS selector should be priority
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test=2");
assertEquals("test=2", cons.getMessageSelector());
// Test setting using JMS destinations
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
assertEquals("test=1", cons.getMessageSelector());
}
Aggregations