Search in sources :

Example 1 with ActiveMQJMSConnectionFactory

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);
}
Also used : TopicDeployment(org.apache.activemq.artemis.rest.topic.TopicDeployment) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) BeforeClass(org.junit.BeforeClass)

Example 2 with ActiveMQJMSConnectionFactory

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;
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration)

Example 3 with ActiveMQJMSConnectionFactory

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();
}
Also used : DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) TransactionManager(javax.transaction.TransactionManager) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 4 with ActiveMQJMSConnectionFactory

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);
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 5 with ActiveMQJMSConnectionFactory

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);
    }
}
Also used : ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ActiveMQJMSConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)13 Connection (javax.jms.Connection)12 Test (org.junit.Test)11 Session (javax.jms.Session)9 ConnectionFactory (javax.jms.ConnectionFactory)8 MessageProducer (javax.jms.MessageProducer)7 Destination (javax.jms.Destination)6 JMSException (javax.jms.JMSException)6 ConnectionFactoryFactory (org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory)6 DestinationFactory (org.apache.activemq.artemis.jms.bridge.DestinationFactory)6 TransactionManager (javax.transaction.TransactionManager)5 JMSBridgeImpl (org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl)5 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)5 MessageConsumer (javax.jms.MessageConsumer)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 HashMap (java.util.HashMap)2