Package org.codehaus.activemq

Examples of org.codehaus.activemq.ActiveMQConnectionFactory


* @version $Revision: 1.1 $
*/
public class EmberTopicSendReceiveTwoConnectionsTest extends JmsTopicSendReceiveWithTwoConnectionsTest {

    protected ActiveMQConnectionFactory createConnectionFactory() {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
        factory.setBrokerURL("nio://localhost:61618");
        factory.setUseEmbeddedBroker(true);
        return factory;
    }
View Full Code Here


* @version $Revision: 1.2 $
*/
public class EmberTopicSendReceiveTest extends JmsTopicSendReceiveTest {

    protected ActiveMQConnectionFactory createConnectionFactory() {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
        factory.setBrokerURL("nio://localhost:61801");
        factory.setUseEmbeddedBroker(true);
        return factory;
    }
View Full Code Here

        addResource(session);
        return session;
    }

    protected ActiveMQConnectionFactory createFactory() {
        ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory(getUrl());
        if (embeddedBroker) {
            answer.setUseEmbeddedBroker(true);
        }
        return answer;
    }
View Full Code Here

    private String topicPrefix = "topic.";

    public Context getInitialContext(Hashtable environment) throws NamingException {
        // lets create a factory
        Map data = new ConcurrentHashMap();
        ActiveMQConnectionFactory factory = createConnectionFactory(environment);

        String[] names = getConnectionFactoryNames(environment);
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            data.put(name, factory);
        }
       
        // Bind jms/DURABLE_SUB_CONNECTION_FACTORY to be a ConnectionFactory that can be used for durable subscriptions.
        ActiveMQConnectionFactory durableFactory = createDurableConnectionFactory(environment);
        Map jmsContext = new ConcurrentHashMap();
        jmsContext.put("DURABLE_SUB_CONNECTION_FACTORY", durableFactory);
        data.put("jms", new ReadOnlyContext(environment, jmsContext));

        createQueues(data, environment);
View Full Code Here

            }
        }
    }

    protected ActiveMQConnectionFactory createDurableConnectionFactory(Hashtable environment) {
        ActiveMQConnectionFactory answer = createConnectionFactory(environment);
        if (answer.getClientID() == null || answer.getClientID().length() == 0) {
            answer.setClientID("clientid");
        }
        return answer;
    }
View Full Code Here

    /**
     * Factory method to create a new connection factory from the given environment
     */
    protected ActiveMQConnectionFactory createConnectionFactory(Hashtable environment) {
        ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
        Properties properties = new Properties();
        properties.putAll(environment);
        answer.setProperties(properties);
        return answer;
    }
View Full Code Here

        }
        return session;
    }

    protected Connection createConnection() throws JMSException, Exception {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, pwd, url);
        Connection connection = connectionFactory.createConnection();
        if (durable) {
            connection.setClientID(clientID);
        }
        connection.start();
        return connection;
View Full Code Here

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
        ConnectionFactory fac = new ActiveMQConnectionFactory("vm://localhost");
        producerConnection = fac.createConnection();
        Session s = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination dest = s.createTopic(getClass().getName());
        MessageProducer producer = s.createProducer(dest);
        consumerConnection = fac.createConnection();
        s = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = s.createConsumer(dest);
        consumerConnection.start();
        out = new DataOutputStream(new JMSOutputStream(producer));
        in = new DataInputStream(new JMSInputStream(consumer));
View Full Code Here

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

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

        String topicName = "TestTopic";
        String clientID = getName();
        String subscriberName = "MySubscriber:"+System.currentTimeMillis();

        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;

        // Create the new connection before closing to avoid the broker shutting down.
        // now create a new Connection, Session &  Producer, send some messages & then close
        Connection t = connectionFactory.createConnection();       
        connection.close();
        connection = t;
       
        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;

        // Now (re)register the Durable subscriber, setup a listener and wait for messages that should
        // have been published by the previous producer
        t = connectionFactory.createConnection();       
        connection.close();
        connection = t;
       
        connection.setClientID(clientID);
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
View Full Code Here

            } catch (NamingException e) {
                throw new JMSException("Error creating InitialContext ", e.toString());
            }
        } else {
            //Used to create a session from the default MQ server ActiveMQConnectionFactory.
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);

            if (embeddedBroker) {
                factory.setUseEmbeddedBroker(true);
            }

            factory.setTurboBoost(true);
            return factory.createConnection();
        }
    }
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.