Example usage for javax.jms Connection start

List of usage examples for javax.jms Connection start

Introduction

In this page you can find the example usage for javax.jms Connection start.

Prototype


void start() throws JMSException;

Source Link

Document

Starts (or restarts) a connection's delivery of incoming messages.

Usage

From source file:org.apache.activemq.broker.region.cursors.KahaDBPendingMessageCursorTest.java

/**
 * Test that the the counter restores size and works after restart and more
 * messages are published/*  w  ww  .  j  av  a2s  .  c o  m*/
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testNonPersistentDurableMessageSize() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();

    Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
    connection.setClientID("clientId");
    connection.start();
    Topic topic = publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.NON_PERSISTENT);

    SubscriptionKey subKey = new SubscriptionKey("clientId", "sub1");

    // verify the count and size
    verifyPendingStats(topic, subKey, 200, publishedMessageSize.get());
    verifyStoreStats(topic, 0, 0);
}

From source file:org.apache.falcon.messaging.FeedProducerTest.java

private void consumer() throws JMSException {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(BROKER_URL);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(TOPIC_NAME);
    MessageConsumer consumer = session.createConsumer(destination);

    latch.countDown();/* ww  w.j a  va 2s  . c  o m*/
    verifyMesssage(consumer);

    connection.close();
}

From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java

private Connection createConnection() throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
            "vm://localhost?jms.prefetchPolicy.all=0");
    factory.setAlwaysSyncSend(true);//from   www.j  av a 2s. co  m
    Connection connection = factory.createConnection();
    connection.start();

    return connection;
}

From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java

private void putQueue(List<String> events) throws Exception {
    ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL);
    Connection connection = factory.createConnection();
    connection.start();

    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(DESTINATION_NAME);
    MessageProducer producer = session.createProducer(destination);

    for (String event : events) {
        TextMessage message = session.createTextMessage();
        message.setText(event);//  w ww . j av a2  s  .c  om
        producer.send(message);
    }
    session.commit();
    session.close();
    connection.close();
}

From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java

private void putTopic(List<String> events) throws Exception {
    ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL);
    Connection connection = factory.createConnection();
    connection.start();

    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createTopic(DESTINATION_NAME);
    MessageProducer producer = session.createProducer(destination);

    for (String event : events) {
        TextMessage message = session.createTextMessage();
        message.setText(event);//from   w w w.  j  ava  2  s.c o  m
        producer.send(message);
    }
    session.commit();
    session.close();
    connection.close();
}

From source file:org.apache.activemq.broker.region.cursors.KahaDBPendingMessageCursorTest.java

/**
 * Test that the the counter restores size and works after restart and more
 * messages are published/*from   ww w  .  ja va2 s.  c  om*/
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testDurableMessageSizeAfterRestartAndPublish() throws Exception {
    AtomicLong publishedMessageSize = new AtomicLong();

    Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
    connection.setClientID("clientId");
    connection.start();
    Topic topic = publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT);

    SubscriptionKey subKey = new SubscriptionKey("clientId", "sub1");

    // verify the count and size
    verifyPendingStats(topic, subKey, 200, publishedMessageSize.get());
    verifyStoreStats(topic, 200, publishedMessageSize.get());

    // stop, restart broker and publish more messages
    stopBroker();
    this.setUpBroker(false);

    connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
    connection.setClientID("clientId");
    connection.start();

    topic = publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize,
            DeliveryMode.PERSISTENT);

    // verify the count and size
    verifyPendingStats(topic, subKey, 400, publishedMessageSize.get());
    verifyStoreStats(topic, 400, publishedMessageSize.get());

}

From source file:org.apache.activemq.apollo.JmsQueueBrowserTest.java

public void testQueueBrowserWith2Consumers() throws Exception {
    final int numMessages = 1000;
    //        connection.setAlwaysSyncSend(false);
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    ActiveMQQueue destination = new ActiveMQQueue("TEST");
    ActiveMQQueue destinationPrefetch10 = new ActiveMQQueue("TEST?jms.prefetchSize=10");
    ActiveMQQueue destinationPrefetch1 = new ActiveMQQueue("TEST?jms.prefetchsize=1");
    connection.start();/* ww  w .  j av  a  2 s.  c o  m*/

    Connection connection2 = factory.createConnection(userName, password);
    connection2.start();
    connections.add(connection2);
    Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);

    MessageProducer producer = session.createProducer(destination);
    MessageConsumer consumer = session.createConsumer(destinationPrefetch10);

    for (int i = 0; i < numMessages; i++) {
        TextMessage message = session.createTextMessage("Message: " + i);
        producer.send(message);
    }

    QueueBrowser browser = session2.createBrowser(destinationPrefetch1);
    Enumeration<Message> browserView = browser.getEnumeration();

    List<Message> messages = new ArrayList<Message>();
    for (int i = 0; i < numMessages; i++) {
        Message m1 = consumer.receive(5000);
        assertNotNull("m1 is null for index: " + i, m1);
        messages.add(m1);
    }

    int i = 0;
    for (; i < numMessages && browserView.hasMoreElements(); i++) {
        Message m1 = messages.get(i);
        Message m2 = browserView.nextElement();
        assertNotNull("m2 is null for index: " + i, m2);
        assertEquals(m1.getJMSMessageID(), m2.getJMSMessageID());
    }

    // currently browse max page size is ignored for a queue browser consumer
    // only guarantee is a page size - but a snapshot of pagedinpending is
    // used so it is most likely more
    assertTrue("got at least our expected minimum in the browser: ", i > 200);

    assertFalse("nothing left in the browser", browserView.hasMoreElements());
    assertNull("consumer finished", consumer.receiveNoWait());
}

From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTest.java

@Before
public void before() throws Exception {
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
            "vm://localhost?broker.persistent=false&broker.useJmx=false");
    Connection connection = connectionFactory.createConnection();
    connection.start();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

}

From source file:com.linagora.obm.sync.TestQueueManager.java

@Test
public void testConsumeLater() throws Exception {
    String testText = "test text";

    writeMessageOnTopic(testText, TOPIC, queueManager);

    Connection connection = createManagedConnection();
    connection.start();
    Session consumerSession = createManagedSession(connection);
    MessageConsumer consumer = queueManager.createConsumerOnTopic(consumerSession, TOPIC);
    TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT);
    Assert.assertNull(messageReceived);/* www  .j  a va  2 s .  c  o  m*/
}

From source file:com.linagora.obm.sync.TestQueueManager.java

@Test
public void testSimple() throws Exception {
    String testText = "test text";

    Connection connection = createManagedConnection();
    connection.start();
    Session consumerSession = createManagedSession(connection);
    MessageConsumer consumer = queueManager.createConsumerOnTopic(consumerSession, TOPIC);

    writeMessageOnTopic(testText, TOPIC, queueManager);

    TextMessage messageReceived = (TextMessage) consumer.receive(TIMEOUT);
    Assert.assertEquals(testText, messageReceived.getText());
}