use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testCloseSendConnection.
public void testCloseSendConnection() throws Exception {
String brokerName = "closeSend";
BrokerService broker = BrokerFactory.createBroker(new URI("broker:(tcp://localhost:0)/" + brokerName));
broker.start();
broker.waitUntilStarted();
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri());
XAConnection connection = (XAConnection) cf.createConnection();
connection.start();
XASession session = connection.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
connection.close();
// comment out this check as it doesn't apply to artemis
// assertTransactionGoneFromBroker(tid);
broker.stop();
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testSessionCloseTransactionalSendReceive.
public void testSessionCloseTransactionalSendReceive() throws Exception {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
XAConnection connection1 = (XAConnection) cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
session.close();
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session = connection1.createXASession();
MessageConsumer consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
session.close();
assertNotNull(receivedMessage);
assertEquals(getName(), receivedMessage.getText());
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session = connection1.createXASession();
consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
assertNull(consumer.receive(1000));
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
}
use of org.apache.activemq.command.ActiveMQQueue in project activemq-artemis by apache.
the class ActiveMQXAConnectionFactoryTest method testVanilaTransactionalProduceReceive.
public void testVanilaTransactionalProduceReceive() throws Exception {
XAConnection connection1 = null;
try {
ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory("vm://localhost?broker.persistent=false");
connection1 = (XAConnection) cf1.createConnection();
connection1.start();
XASession session = connection1.createXASession();
XAResource resource = session.getXAResource();
Destination dest = new ActiveMQQueue(getName());
// publish a message
Xid tid = createXid();
resource.start(tid, XAResource.TMNOFLAGS);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setText(getName());
producer.send(message);
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session.close();
session = connection1.createXASession();
MessageConsumer consumer = session.createConsumer(dest);
tid = createXid();
resource = session.getXAResource();
resource.start(tid, XAResource.TMNOFLAGS);
TextMessage receivedMessage = (TextMessage) consumer.receive(1000);
assertNotNull(receivedMessage);
assertEquals(getName(), receivedMessage.getText());
resource.end(tid, XAResource.TMSUCCESS);
resource.commit(tid, true);
session.close();
} finally {
if (connection1 != null) {
try {
connection1.close();
} catch (Exception e) {
// ignore
}
}
}
}
use of org.apache.activemq.command.ActiveMQQueue 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.command.ActiveMQQueue 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