List of usage examples for javax.jms Connection setClientID
void setClientID(String clientID) throws JMSException;
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testMessageSizeOneDurablePartialConsumption() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = cf.createConnection(); connection.setClientID("clientId"); connection.start();// w w w. j a va 2 s. co m publishTestMessagesDurable(connection, new String[] { "sub1" }, 200, publishedMessageSize, DeliveryMode.PERSISTENT, false); verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get()); // consume partial messages consumeDurableTestMessages(connection, "sub1", 50, publishedMessageSize); // 150 should be left verifyPendingStats(defaultTopicName, 150, publishedMessageSize.get()); // We don't really know the size here but it should be smaller than before // so take an average verifyPendingDurableStats(defaultTopicName, 150, (long) (.75 * publishedMessageSize.get())); connection.close(); }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testMessageSizeTwoDurables() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = cf.createConnection(); connection.setClientID("clientId"); connection.start();/* ww w . j ava 2s. c o m*/ publishTestMessagesDurable(connection, new String[] { "sub1", "sub2" }, 200, publishedMessageSize, DeliveryMode.PERSISTENT, false); // verify the count and size - double because two durables so two queue // bindings verifyPendingStats(defaultTopicName, 400, 2 * publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 400, 2 * publishedMessageSize.get()); // consume messages just for sub1 consumeDurableTestMessages(connection, "sub1", 200, publishedMessageSize); // There is still a durable that hasn't consumed so the messages should // exist verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get()); connection.close(); // restart and verify load this.killServer(); this.restartServer(); verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get()); }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testMessageSizeSharedDurable() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = cf.createConnection(); connection.setClientID("clientId"); connection.start();/*from www . ja va 2s. co m*/ // The publish method will create a second shared consumer Session s = connection.createSession(); MessageConsumer c = s.createSharedDurableConsumer(s.createTopic(defaultTopicName), "sub1"); publishTestMessagesDurable(connection, new String[] { "sub1", }, 200, publishedMessageSize, DeliveryMode.PERSISTENT, true); // verify the count and size - double because two durables so two queue // bindings verifyPendingStats(defaultTopicName, 200, publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 200, publishedMessageSize.get()); c.close(); // consume messages for sub1 consumeDurableTestMessages(connection, "sub1", 200, publishedMessageSize); verifyPendingStats(defaultTopicName, 0, publishedMessageSize.get()); verifyPendingDurableStats(defaultTopicName, 0, publishedMessageSize.get()); connection.close(); }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
protected void publishTestTopicMessages(int publishSize, int deliveryMode, AtomicLong publishedMessageSize) throws Exception { // create a new queue Connection connection = cf.createConnection(); connection.setClientID("clientId2"); connection.start();/*from w w w.j av a 2 s . c o m*/ // Start the connection Session session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(defaultTopicName); try { // publish a bunch of non-persistent messages to fill up the temp // store MessageProducer prod = session.createProducer(topic); prod.setDeliveryMode(deliveryMode); for (int i = 0; i < publishSize; i++) { prod.send( createMessage(i, session, JournalPendingMessageTest.maxMessageSize, publishedMessageSize)); } } finally { 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 w w w . j av a2 s . co m*/ * * @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.broker.region.cursors.KahaDBPendingMessageCursorTest.java
/** * Test that the the counter restores size and works after restart and more * messages are published/*from w w w . jav a2 s .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.activemq.store.kahadb.MultiKahaDBQueueDeletionTest.java
@Override protected void createConsumer(ActiveMQDestination dest) throws JMSException { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerConnectURI); Connection connection = factory.createConnection(); connection.setClientID("client1"); connection.start();//from ww w . j av a2s . c om Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); session.createConsumer(dest); }
From source file:org.apache.activemq.store.kahadb.MultiKahaDBTopicDeletionTest.java
@Override protected void createConsumer(ActiveMQDestination dest) throws JMSException { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerConnectURI); Connection connection = factory.createConnection(); connection.setClientID("client1"); connection.start();/*from w w w . j av a2 s . c o m*/ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); session.createDurableSubscriber((Topic) dest, "sub1"); }
From source file:org.apache.activemq.store.kahadb.SubscriptionRecoveryTest.java
private void createInactiveDurableSub(Topic topic) throws Exception { Connection connection = cf.createConnection(); connection.setClientID("Inactive"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createDurableSubscriber(topic, "Inactive"); consumer.close();/*from ww w .j a v a2s . c om*/ connection.close(); }
From source file:org.apache.activemq.store.kahadb.SubscriptionRecoveryTest.java
private void consumeDurableMessages(Topic topic, int count) throws Exception { Connection connection = cf.createConnection(); connection.setClientID("Inactive"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createDurableSubscriber(topic, "Inactive"); connection.start();//from w w w . ja v a 2s . c om for (int i = 0; i < count; ++i) { if (consumer.receive(TimeUnit.SECONDS.toMillis(10)) == null) { fail("should have received a message"); } } consumer.close(); connection.close(); }