use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class JMSBridgeImplTest method testStartWithSpecificTCCL.
@Test
public void testStartWithSpecificTCCL() throws Exception {
MockContextClassLoader mockTccl = setMockTCCL();
try {
final AtomicReference<Connection> sourceConn = new AtomicReference<>();
ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
private static final long serialVersionUID = -8866390811966688830L;
@Override
public Connection createConnection() throws JMSException {
sourceConn.set(super.createConnection());
return sourceConn.get();
}
};
// Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
failingSourceCF.setReconnectAttempts(0);
failingSourceCF.setBlockOnNonDurableSend(true);
failingSourceCF.setBlockOnDurableSend(true);
ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newTCCLAwareConnectionFactoryFactory(failingSourceCF);
ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
TransactionManager tm = JMSBridgeImplTest.newTransactionManager();
JMSBridgeImpl bridge = new JMSBridgeImpl();
Assert.assertNotNull(bridge);
bridge.setSourceConnectionFactoryFactory(sourceCFF);
bridge.setSourceDestinationFactory(sourceDF);
bridge.setTargetConnectionFactoryFactory(targetCFF);
bridge.setTargetDestinationFactory(targetDF);
bridge.setFailureRetryInterval(10);
bridge.setMaxRetries(2);
bridge.setMaxBatchSize(1);
bridge.setMaxBatchTime(-1);
bridge.setTransactionManager(tm);
bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
Assert.assertFalse(bridge.isStarted());
bridge.start();
Assert.assertTrue(bridge.isStarted());
unsetMockTCCL(mockTccl);
tcclClassFound.set(false);
sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
Thread.sleep(4 * bridge.getFailureRetryInterval());
// reconnection must have succeeded
Assert.assertTrue(bridge.isStarted());
bridge.stop();
Assert.assertFalse(bridge.isStarted());
assertTrue(tcclClassFound.get());
} finally {
if (mockTccl != null)
unsetMockTCCL(mockTccl);
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class ArtemisJMSClientFeatureIT method testArtemisJMSClient.
@Test
public void testArtemisJMSClient() throws Exception {
// setup connection
ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
try (Connection connection = cf.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
connection.start();
Queue queue = ActiveMQJMSClient.createQueue("artemisJMSClientFeatureITQueue");
MessageProducer producer = session.createProducer(queue);
// send message
String textMessage = "This is a text message";
TextMessage message = session.createTextMessage(textMessage);
producer.send(message);
// receive message and assert
MessageConsumer messageConsumer = session.createConsumer(queue);
TextMessage messageReceived = (TextMessage) messageConsumer.receive(100);
assertEquals(textMessage, messageReceived.getText());
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class JMSUtil method createFactory.
public static ConnectionFactory createFactory(final String connectorFactory, final long connectionTTL, final long clientFailureCheckPeriod) throws JMSException {
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setBlockOnAcknowledge(true);
cf.setConnectionTTL(connectionTTL);
cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
return cf;
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class JMSUtil method createConnection.
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static Connection createConnection(final String connectorFactory) throws JMSException {
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));
cf.setBlockOnNonDurableSend(true);
cf.setBlockOnDurableSend(true);
cf.setBlockOnAcknowledge(true);
return cf.createConnection();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class PagingOrderTest method testPagingOverCreatedDestinationTopics.
@Test
public void testPagingOverCreatedDestinationTopics() throws Exception {
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
InVMNamingContext context = new InVMNamingContext();
jmsServer.setRegistry(new JndiBindingRegistry(context));
jmsServer.start();
jmsServer.createTopic(true, "tt", "/topic/TT");
server.getActiveMQServerControl().addAddressSettings("TT", "DLQ", "DLQ", -1, false, 5, 1024 * 1024, 1024 * 10, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
Connection conn = cf.createConnection();
conn.setClientID("tst");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) context.lookup("/topic/TT");
sess.createDurableSubscriber(topic, "t1");
MessageProducer prod = sess.createProducer(topic);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage txt = sess.createTextMessage("TST");
prod.send(txt);
PagingStore store = server.getPagingManager().getPageStore(new SimpleString("TT"));
assertEquals(1024 * 1024, store.getMaxSize());
assertEquals(10 * 1024, store.getPageSizeBytes());
jmsServer.stop();
server = createServer(true, config, PAGE_SIZE, -1, new HashMap<String, AddressSettings>());
jmsServer = new JMSServerManagerImpl(server);
context = new InVMNamingContext();
jmsServer.setRegistry(new JndiBindingRegistry(context));
jmsServer.start();
AddressSettings settings = server.getAddressSettingsRepository().getMatch("TT");
assertEquals(1024 * 1024, settings.getMaxSizeBytes());
assertEquals(10 * 1024, settings.getPageSizeBytes());
assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());
store = server.getPagingManager().getPageStore(new SimpleString("TT"));
conn.close();
server.stop();
}
Aggregations