use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class SelectorTest method setup.
@BeforeClass
public static void setup() throws Exception {
connectionFactory = new ActiveMQJMSConnectionFactory(manager.getQueueManager().getServerLocator());
System.out.println("Queue name: " + prefixedTopicName);
TopicDeployment deployment = new TopicDeployment();
deployment.setDuplicatesAllowed(true);
deployment.setDurableSend(false);
deployment.setName(topicName);
manager.getTopicManager().deploy(deployment);
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class AutoGroupingTest method getCF.
@Override
protected ConnectionFactory getCF() throws Exception {
ActiveMQJMSConnectionFactory cf1 = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
cf1.setAutoGroup(true);
return cf1;
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class JMSBridgeImplTest method testStartWithFailureThenSuccess.
@Test
public void testStartWithFailureThenSuccess() throws Exception {
ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
private static final long serialVersionUID = 4657153922210359725L;
boolean firstTime = true;
@Override
public Connection createConnection() throws JMSException {
if (firstTime) {
firstTime = false;
throw new JMSException("unable to create a conn");
} else {
return super.createConnection();
}
}
};
// 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.newConnectionFactoryFactory(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();
bridge.setSourceConnectionFactoryFactory(sourceCFF);
bridge.setSourceDestinationFactory(sourceDF);
bridge.setTargetConnectionFactoryFactory(targetCFF);
bridge.setTargetDestinationFactory(targetDF);
// retry after 10 ms
bridge.setFailureRetryInterval(10);
// retry only once
bridge.setMaxRetries(1);
bridge.setMaxBatchSize(1);
bridge.setMaxBatchTime(-1);
bridge.setTransactionManager(tm);
bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);
Assert.assertFalse(bridge.isStarted());
bridge.start();
Thread.sleep(500);
Assert.assertTrue(bridge.isStarted());
Assert.assertFalse(bridge.isFailed());
bridge.stop();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class PostOrder method main.
public static void main(String[] args) throws Exception {
ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
Destination destination = ActiveMQDestination.fromPrefixedName("queue://orders");
try (Connection conn = factory.createConnection()) {
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
ObjectMessage message = session.createObjectMessage();
Order order = new Order("Bill", "$199.99", "iPhone4");
message.setObject(order);
producer.send(message);
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory in project activemq-artemis by apache.
the class ArtemisTransactionalJMSClientFeatureIT method testTransactionalArtemisJMSClient.
@Test
public void testTransactionalArtemisJMSClient() throws Exception {
// setup connection
ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
try (Connection connection = cf.createConnection()) {
connection.start();
Queue queue = ActiveMQJMSClient.createQueue("ArtemisTransactionalJMSClientFeatureITQueue");
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer messageProducer = session.createProducer(queue);
MessageConsumer messageConsumer = session.createConsumer(queue);
// send messages
String textMessage1 = "This is a text message1";
TextMessage message1 = session.createTextMessage(textMessage1);
String textMessage2 = "This is a text message2";
TextMessage message2 = session.createTextMessage(textMessage2);
messageProducer.send(message1);
messageProducer.send(message2);
// assert null before commit
TextMessage receivedMessage = (TextMessage) messageConsumer.receive(10);
assertNull(receivedMessage);
// commit and rollback
session.commit();
receivedMessage = (TextMessage) messageConsumer.receive(10);
assertNotNull(receivedMessage);
session.rollback();
// assert messages
receivedMessage = (TextMessage) messageConsumer.receive(100);
assertEquals(textMessage1, receivedMessage.getText());
receivedMessage = (TextMessage) messageConsumer.receive(100);
assertEquals(textMessage2, receivedMessage.getText());
session.commit();
receivedMessage = (TextMessage) messageConsumer.receive(10);
assertNull(receivedMessage);
}
}
Aggregations