Package org.codehaus.activemq

Examples of org.codehaus.activemq.ActiveMQConnectionFactory


* @version $Revision: 1.4 $
*/
public class SubscribeClosePublishThenConsumeTest extends TestSupport {

    public void testDurableTopic() throws Exception {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setUseEmbeddedBroker(true);

        String topicName = "TestTopic";
        String clientID = "MyClientID";
        String subscriberName = "MySubscriber";

        // TODO remove this hack!
        //Connection dummy = connectionFactory.createConnection();
        //dummy.start();

        Connection connection = connectionFactory.createConnection();
        connection.setClientID(clientID);

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(topicName);

        // this should register a durable subscriber, we then close it to
        // test that we get messages from the producer later on
        TopicSubscriber subscriber = session.createDurableSubscriber(topic, subscriberName);
        connection.start();

        topic = null;
        subscriber.close();
        subscriber = null;

        session.close();
        session = null;

        connection.close();
        connection = null;

        // now create a new Connection, Session &  Producer, send some messages & then close
        connection = connectionFactory.createConnection();
        // connection.setClientID(clientID); // this should not be required for the Producer
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        topic = session.createTopic(topicName);
        MessageProducer producer = session.createProducer(topic);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        TextMessage textMessage = session.createTextMessage("Hello World");
        producer.send(textMessage);
        textMessage = null;

        topic = null;
        session.close();
        session = null;

        connection.close();
        connection = null;

        // Now (re)register the Durable subscriber, setup a listener and wait for messages that should
        // have been published by the previous producer

        connection = connectionFactory.createConnection();
        connection.setClientID(clientID);
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        topic = session.createTopic(topicName);

        subscriber = session.createDurableSubscriber(topic, subscriberName);
View Full Code Here


        destination = createDestination(getClass().getName());
    }

    public ActiveMQConnectionFactory getConnectionFactory() throws Exception {
        String url = "reliable:" + ActiveMQConnection.DEFAULT_URL;
        return new ActiveMQConnectionFactory(url);
    }
View Full Code Here

        assertTrue("No topic created!", topic != null);
    }

    public void testTryToReproduceNullPointerBug() throws Exception {
        String url = bindAddress;
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
        QueueConnection queueConnection = factory.createQueueConnection();
        this.connection = queueConnection;
        QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueSender sender = session.createSender(null); //Unidentified
        Queue receiverQueue = session.createTemporaryQueue();
        QueueReceiver receiver = session.createReceiver(receiverQueue);
View Full Code Here

        queueConnection.start();

    }

    protected Connection createConnection() throws Exception {
        ActiveMQConnectionFactory factory = createConnectionFactory();
        return factory.createConnection();
    }
View Full Code Here

        ActiveMQConnectionFactory factory = createConnectionFactory();
        return factory.createConnection();
    }

    protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
        return new ActiveMQConnectionFactory(broker, "tcp://localhost:61623");
    }
View Full Code Here

            assertMessagesReceivedAreValid(messageLists[i]);
        }
    }

    protected ActiveMQConnectionFactory createConnectionFactory() {
        return new ActiveMQConnectionFactory("vm://localhost");
    }
View Full Code Here

        container.addConnector(url);
        container.addNetworkConnector(new DiscoveryNetworkConnector(container));
        container.start();
        //embedded brokers are resolved by url - so make url unique
        //this confused me tests for a while :-)
        return new ActiveMQConnectionFactory(container,"vm://"+brokerName);
    }
View Full Code Here

    protected Connection createSendConnection() throws JMSException {
        return sendFactory.createConnection();
    }

    protected ActiveMQConnectionFactory createConnectionFactory(String config, String brokerName, String connectUrl) throws JMSException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectUrl);
        factory.setBrokerName(brokerName);
        factory.setUseEmbeddedBroker(true);
        factory.setBrokerContainerFactory(new SpringBrokerContainerFactory(new ClassPathResource(config)));
        return factory;
    }
View Full Code Here

        // configuration of container and all protocolls
        BrokerContainerImpl container = createBroker();

        // start a client
        ActiveMQConnectionFactory factory = new
                ActiveMQConnectionFactory("tcp://localhost:9100");
        factory.start();
        factory.createConnection();

        // stop activemq broker
        container.stop();

        // start activemq broker again
        container = createBroker();

        // start a client again
        factory = new
                ActiveMQConnectionFactory("tcp://localhost:9100");
        factory.start();
        factory.createConnection();

        // stop activemq broker
        container.stop();

    }
View Full Code Here

* @version $Revision: 1.1 $
*/
public class ZeroconfDiscoveryTest extends TestCase {

    public void test1() throws Exception {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("zeroconf:_activemq.broker.development.");

        // use an embedded broker configured via Spring
        connectionFactory.setUseEmbeddedBroker(true);
        connectionFactory.setBrokerContainerFactory(new SpringBrokerContainerFactory(new ClassPathResource("org/codehaus/activemq/usecases/receiver-zeroconf.xml")));

        Connection connection = connectionFactory.createConnection();
        connection.setClientID("Producer1");
        connection.start();

        // now lets close things down
        connection.close();
View Full Code Here

TOP

Related Classes of org.codehaus.activemq.ActiveMQConnectionFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.