Java Code Examples for javax.jms.TopicConnection#start()
The following examples show how to use
javax.jms.TopicConnection#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetworkRemovesSubscriptionsTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testWithSessionAndSubsciberClose() throws Exception { TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); for (int i = 0; i < 100; i++) { TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = subscriberSession.createSubscriber(topic); DummyMessageListener listener = new DummyMessageListener(); subscriber.setMessageListener(listener); subscriber.close(); subscriberSession.close(); } connection.close(); Thread.sleep(1000); Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic); assertNotNull(dest); assertTrue(dest.getConsumers().isEmpty()); }
Example 2
Source File: NetworkRemovesSubscriptionsTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testWithOneSubscriber() throws Exception { TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = subscriberSession.createSubscriber(topic); DummyMessageListener listener = new DummyMessageListener(); subscriber.setMessageListener(listener); subscriber.close(); subscriberSession.close(); connection.close(); Thread.sleep(1000); Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic); assertNotNull(dest); assertTrue(dest.getConsumers().isEmpty()); }
Example 3
Source File: NetworkRemovesSubscriptionsTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testWithoutSessionAndSubsciberClose() throws Exception { TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); for (int i = 0; i < 100; i++) { TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicSubscriber subscriber = subscriberSession.createSubscriber(topic); assertNotNull(subscriber); } connection.close(); Thread.sleep(1000); Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic); assertNotNull(dest); assertTrue(dest.getConsumers().isEmpty()); }
Example 4
Source File: DurableSubscriptionHangTestCase.java From activemq-artemis with Apache License 2.0 | 6 votes |
private Message collectMessagesFromDurableSubscriptionForOneMinute() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://" + brokerName); TopicConnection connection = connectionFactory.createTopicConnection(); connection.setClientID(clientID); TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(topicName); connection.start(); TopicSubscriber subscriber = topicSession.createDurableSubscriber(topic, durableSubName); LOG.info("About to receive messages"); Message message = subscriber.receive(120000); subscriber.close(); connection.close(); LOG.info("collectMessagesFromDurableSubscriptionForOneMinute done"); return message; }
Example 5
Source File: NetworkRemovesSubscriptionsTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
public void testWithSessionCloseOutsideTheLoop() throws Exception { TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); for (int i = 0; i < 100; i++) { TopicSubscriber subscriber = subscriberSession.createSubscriber(topic); DummyMessageListener listener = new DummyMessageListener(); subscriber.setMessageListener(listener); subscriber.close(); } subscriberSession.close(); connection.close(); Thread.sleep(1000); Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic); assertNotNull(dest); assertTrue(dest.getConsumers().isEmpty()); }
Example 6
Source File: SingleConnectionFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testWithTopicConnection() throws JMSException { Connection con = mock(TopicConnection.class); SingleConnectionFactory scf = new SingleConnectionFactory(con); TopicConnection con1 = scf.createTopicConnection(); con1.start(); con1.stop(); con1.close(); TopicConnection con2 = scf.createTopicConnection(); con2.start(); con2.stop(); con2.close(); scf.destroy(); // should trigger actual close verify(con, times(2)).start(); verify(con, times(2)).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
Example 7
Source File: SingleConnectionFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testWithTopicConnection() throws JMSException { Connection con = mock(TopicConnection.class); SingleConnectionFactory scf = new SingleConnectionFactory(con); TopicConnection con1 = scf.createTopicConnection(); con1.start(); con1.stop(); con1.close(); TopicConnection con2 = scf.createTopicConnection(); con2.start(); con2.stop(); con2.close(); scf.destroy(); // should trigger actual close verify(con, times(2)).start(); verify(con, times(2)).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
Example 8
Source File: ConnectionCreateClosePerMessageTest.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
private TopicConnection getTopicConnection(InitialContext initialContext) throws NamingException, JMSException { TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); return connection; }
Example 9
Source File: TopicWildcardTest.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
private void assertNotNullWithPublishSubscribeForTopics(String publishTopicName, String subscribeTopicName) throws Exception { int numberOfMessages = 100; InitialContext initialContext = ClientHelper .getInitialContextBuilder("admin", "admin", "localhost", port) .withTopic(publishTopicName) .withTopic(subscribeTopicName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic subscriberDestination = (Topic) initialContext.lookup(subscribeTopicName); TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination); TopicSession publisherSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic publisherDestination = (Topic) initialContext.lookup(publishTopicName); TopicPublisher publisher = publisherSession.createPublisher(publisherDestination); for (int i = 0; i < numberOfMessages; i++) { publisher.publish(publisherSession.createTextMessage("Test message " + i)); } publisherSession.close(); for (int i = 0; i < numberOfMessages; i++) { Message message = subscriber.receive(1000); Assert.assertNotNull(message, "Message #" + i + " was not received"); } subscriberSession.close(); connection.close(); }
Example 10
Source File: TopicSubscriberTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void messageDeliveredToAllSubscribers() throws Exception { Topic topic = createTopic(getTestName()); final TopicConnection connection = getTopicConnection(); try { final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); final TopicPublisher producer = session.createPublisher(topic); final TopicSubscriber subscriber1 = session.createSubscriber(topic); assertEquals("Unexpected subscriber1 topic", topic.getTopicName(), subscriber1.getTopic().getTopicName()); final TopicSubscriber subscriber2 = session.createSubscriber(topic); assertEquals("Unexpected subscriber2 topic", topic.getTopicName(), subscriber2.getTopic().getTopicName()); connection.start(); String messageText = "Test Message"; producer.send(session.createTextMessage(messageText)); final Message subscriber1Message = subscriber1.receive(getReceiveTimeout()); final Message subscriber2Message = subscriber2.receive(getReceiveTimeout()); assertTrue("TextMessage should be received by subscriber1", subscriber1Message instanceof TextMessage); assertEquals(messageText, ((TextMessage) subscriber1Message).getText()); assertTrue("TextMessage should be received by subscriber2", subscriber2Message instanceof TextMessage); assertEquals(messageText, ((TextMessage) subscriber2Message).getText()); } finally { connection.close(); } }
Example 11
Source File: TimeToLiveTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void testActiveTTLWithDurableSubscription() throws Exception { long timeToLiveMillis = getReceiveTimeout(); String subscriptionName = getTestName() + "_sub"; Topic topic = createTopic(getTestName()); TopicConnection connection = getTopicConnection(); try { Session session = connection.createSession(true, Session.SESSION_TRANSACTED); TopicSubscriber durableSubscriber = session.createDurableSubscriber(topic, subscriptionName); MessageProducer producer = session.createProducer(topic); producer.setTimeToLive(timeToLiveMillis); producer.send(session.createTextMessage("A")); producer.setTimeToLive(0); producer.send(session.createTextMessage("B")); session.commit(); Thread.sleep(timeToLiveMillis); connection.start(); Message message = durableSubscriber.receive(getReceiveTimeout()); assertTrue("TextMessage should be received", message instanceof TextMessage); assertEquals("Unexpected message received", "B", ((TextMessage)message).getText()); } finally { connection.close(); } }
Example 12
Source File: AuthenticationTest.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
@Parameters({ "broker-port", "test-username", "test-password" }) @Test(description = "Test valid user password with special characters") public void testPasswordWithSpecialCharacters(String port, String testUsername, String testPassword) throws Exception { String topicName = "MyTopic1"; InitialContext initialContext = ClientHelper .getInitialContextBuilder(testUsername, testPassword, "localhost", port).withTopic(topicName).build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext .lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); connection.close(); }
Example 13
Source File: SingleConnectionFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage() throws JMSException { TopicConnectionFactory cf = mock(TopicConnectionFactory.class); TopicConnection con = mock(TopicConnection.class); TopicSession txSession = mock(TopicSession.class); TopicSession nonTxSession = mock(TopicSession.class); given(cf.createTopicConnection()).willReturn(con); given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession); given(txSession.getTransacted()).willReturn(true); given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession); CachingConnectionFactory scf = new CachingConnectionFactory(cf); scf.setReconnectOnException(false); Connection con1 = scf.createTopicConnection(); Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE); session1.getTransacted(); session1.close(); // should lead to rollback session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE); session1.close(); con1.start(); TopicConnection con2 = scf.createTopicConnection(); Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE); session2.close(); session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE); session2.getTransacted(); session2.close(); con2.start(); con1.close(); con2.close(); scf.destroy(); // should trigger actual close verify(txSession).close(); verify(nonTxSession).close(); verify(con).start(); verify(con).stop(); verify(con).close(); }
Example 14
Source File: DurableTopicMessagesOrderTest.java From ballerina-message-broker with Apache License 2.0 | 4 votes |
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"}) @Test public void test1966DurableTopicMessagesOrderSingleSubscriber(String port, String adminUsername, String adminPassword, String brokerHostname) throws NamingException, JMSException { String topicName = "test1966DurableTopicMessagesOrderSingleSubscriber"; List<String> subscriberOneMessages = new ArrayList<>(); int numberOfMessages = 1966; InitialContext initialContext = ClientHelper .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port) .withTopic(topicName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); // Initialize subscriber TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic subscriberDestination = (Topic) initialContext.lookup(topicName); TopicSubscriber subscriber = subscriberSession.createDurableSubscriber(subscriberDestination, "1966_1"); // publish 1966 messages TopicSession producerSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher producer = producerSession.createPublisher(subscriberDestination); for (int i = 0; i < numberOfMessages; i++) { producer.publish(producerSession.createTextMessage(String.valueOf(i))); } producerSession.close(); for (int i = 0; i < numberOfMessages; i++) { TextMessage message = (TextMessage) subscriber.receive(5000); Assert.assertNotNull(message, "Message #" + i + " was not received"); subscriberOneMessages.add(message.getText()); } subscriberSession.close(); connection.close(); // verify order is preserved boolean isOrderPreserved = true; for (int i = 0; i < numberOfMessages; i++) { if (!(i == Integer.parseInt(subscriberOneMessages.get(i)))) { isOrderPreserved = false; break; } } Assert.assertTrue(isOrderPreserved, "Topic messages order not preserved for single subscriber."); }
Example 15
Source File: MultipleTopicSubscriberTestCase.java From ballerina-message-broker with Apache License 2.0 | 4 votes |
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"}) @Test public void testMultipleTopicSubscribersOnSameSession(String port, String adminUsername, String adminPassword, String brokerHostname) throws NamingException, JMSException, InterruptedException { String queueName = "testMultipleTopicSubscribersOnSameSession"; InitialContext initialContext = ClientHelper .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port) .withTopic(queueName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE); Topic topic = (Topic) initialContext.lookup(queueName); int numberOfConsumers = 3; int messagesPerConsumer = 1000; int maxNumberOfMessages = numberOfConsumers * messagesPerConsumer; LinkedBlockingQueue<MessageResult> receiveQueue = new LinkedBlockingQueue<>(maxNumberOfMessages); TopicSubscriber consumers[] = new TopicSubscriber[numberOfConsumers]; int messageCount[] = new int[numberOfConsumers]; for (int consumerIndex = 0; consumerIndex < numberOfConsumers; consumerIndex++) { consumers[consumerIndex] = subscriberSession.createSubscriber(topic); int finalConsumerIndex = consumerIndex; consumers[consumerIndex].setMessageListener(message -> { messageCount[finalConsumerIndex]++; try { message.acknowledge(); } catch (JMSException e) { LOGGER.error("Message acknowledging failed.", e); } receiveQueue.offer(new MessageResult(message, finalConsumerIndex)); }); } // publish messages with property. TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); TopicPublisher producer = producerSession.createPublisher(topic); TextMessage textMessage; String consumerMessage = "testMessage"; for (int i = 0; i < messagesPerConsumer; i++) { textMessage = producerSession.createTextMessage(consumerMessage); producer.send(textMessage); } for (int i = 0; i < maxNumberOfMessages; i++) { MessageResult result = receiveQueue.poll(5, TimeUnit.SECONDS); if (result == null) { StringBuilder countSummary = new StringBuilder(); for (int consumerIndex = 0; consumerIndex < numberOfConsumers; consumerIndex++) { countSummary.append("Consumer ") .append(consumerIndex) .append(" received ") .append(messageCount[consumerIndex]) .append(" messages, "); } Assert.fail("Messages stopped receiving after " + i + " iterations. " + countSummary.toString()); } else { TextMessage textMessage1 = (TextMessage) result.getMessage(); Assert.assertEquals(textMessage1.getText(), consumerMessage, "Incorrect message received for consumer " + result.getConsumerId()); } } for (int consumerIndex = 0; consumerIndex < numberOfConsumers; consumerIndex++) { Assert.assertEquals(messageCount[consumerIndex], messagesPerConsumer, "Message " + messageCount[consumerIndex] + " received for consumer " + consumerIndex + "."); } producer.close(); for (int consumerIndex = 0; consumerIndex < numberOfConsumers; consumerIndex++) { consumers[consumerIndex].close(); } connection.close(); }
Example 16
Source File: BDBUpgradeTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
/** * Test that the DurableSubscription without selector was successfully * transfered to the new store, and functions as expected with continued use. */ @Test public void testDurableSubscriptionWithoutSelector() throws Exception { TopicConnection connection = getTopicConnection(); try { connection.start(); TopicSession session = connection.createTopicSession(true, Session.SESSION_TRANSACTED); Topic topic = session.createTopic(TOPIC_NAME); TopicPublisher publisher = session.createPublisher(topic); int index = ThreadLocalRandom.current().nextInt(); Message messageA = session.createTextMessage("A"); messageA.setIntProperty("ID", index); messageA.setStringProperty("testprop", "false"); publisher.publish(messageA); Message messageB = session.createTextMessage("B"); messageB.setIntProperty("ID", index); messageB.setStringProperty("testprop", "true"); publisher.publish(messageB); session.commit(); TopicSubscriber subscriber = session.createDurableSubscriber(topic, SUB_NAME); Message migrated = subscriber.receive(getReceiveTimeout()); assertThat("Failed to receive migrated message", migrated, is(notNullValue())); Message receivedA = subscriber.receive(getReceiveTimeout()); session.commit(); assertThat("Failed to receive published message A", receivedA, is(notNullValue())); assertThat("Message A is not Text message", receivedA, is(instanceOf(TextMessage.class))); assertThat("Unexpected text for A", ((TextMessage) receivedA).getText(), is(equalTo("A"))); assertThat("Unexpected index", receivedA.getIntProperty("ID"), is(equalTo(index))); Message receivedB = subscriber.receive(getReceiveTimeout()); session.commit(); assertThat("Failed to receive published message B", receivedB, is(notNullValue())); assertThat("Message B is not Text message", receivedB, is(instanceOf(TextMessage.class))); assertThat("Unexpected text for B", ((TextMessage) receivedB).getText(), is(equalTo("B"))); assertThat("Unexpected index for B", receivedB.getIntProperty("ID"), is(equalTo(index))); session.commit(); session.close(); } finally { connection.close(); } }
Example 17
Source File: JMSSelectorTest.java From ballerina-message-broker with Apache License 2.0 | 4 votes |
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"}) @Test public void testPositiveJMSSelectorConsumerProducer(String port, String adminUsername, String adminPassword, String brokerHostname) throws NamingException, JMSException { String queueName = "testPositiveJMSSelectorConsumerProducer"; InitialContext initialContext = ClientHelper .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port) .withTopic(queueName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = (Topic) initialContext.lookup(queueName); // Subscribe with a selector String propertyName = "MyProperty"; String propertyValue = "propertyValue"; String jmsPropertySelector = propertyName + " = '" + propertyValue + "'"; TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false); // publish messages with property TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); TopicPublisher producer = producerSession.createPublisher(topic); int numberOfMessages = 100; for (int i = 0; i < numberOfMessages; i++) { TextMessage textMessage = producerSession.createTextMessage("Test message " + i); textMessage.setStringProperty(propertyName, propertyValue); producer.send(textMessage); } // consume messages for (int i = 0; i < numberOfMessages; i++) { Message message = consumer.receive(1000); Assert.assertNotNull(message, "Message #" + i + " was not received"); } producerSession.close(); connection.close(); }
Example 18
Source File: JMSSelectorTest.java From ballerina-message-broker with Apache License 2.0 | 4 votes |
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"}) @Test public void testNegativeJMSSelectorConsumerProducer(String port, String adminUsername, String adminPassword, String brokerHostname) throws NamingException, JMSException { String queueName = "testNegativeJMSSelectorConsumerProducer"; InitialContext initialContext = ClientHelper .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port) .withTopic(queueName) .build(); TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); TopicConnection connection = connectionFactory.createTopicConnection(); connection.start(); TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = (Topic) initialContext.lookup(queueName); // Subscribe with a selector String propertyName = "MyProperty"; String propertyValue = "propertyValue"; String jmsPropertySelector = propertyName + " = '" + propertyValue + "'"; TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false); // publish messages with property TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); TopicPublisher producer = producerSession.createPublisher(topic); // Send messages with a different property value int numberOfMessages = 100; for (int i = 0; i < numberOfMessages; i++) { TextMessage textMessage = producerSession.createTextMessage("Test message " + i); textMessage.setStringProperty(propertyName, propertyValue + "-1"); producer.send(textMessage); } // consume messages Message message = consumer.receive(100); Assert.assertNull(message, "Message received. Shouldn't receive any messages."); producerSession.close(); connection.close(); }
Example 19
Source File: BDBUpgradeTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
/** * Test that the selector applied to the DurableSubscription was successfully * transferred to the new store, and functions as expected with continued use * by monitoring message count while sending new messages to the topic and then * consuming them. */ @Test public void testSelectorDurability() throws Exception { TopicConnection connection = getTopicConnection(); try { connection.start(); TopicSession session = connection.createTopicSession(true, Session.SESSION_TRANSACTED); Topic topic = session.createTopic(SELECTOR_TOPIC_NAME); TopicPublisher publisher = session.createPublisher(topic); int index = ThreadLocalRandom.current().nextInt(); Message messageA = session.createTextMessage("A"); messageA.setIntProperty("ID", index); messageA.setStringProperty("testprop", "false"); publisher.publish(messageA); Message messageB = session.createTextMessage("B"); messageB.setIntProperty("ID", index); messageB.setStringProperty("testprop", "true"); publisher.publish(messageB); session.commit(); TopicSubscriber subscriber = session.createDurableSubscriber(topic, SELECTOR_SUB_NAME, "testprop='true'", false); Message migrated = subscriber.receive(getReceiveTimeout()); assertThat("Failed to receive migrated message", migrated, is(notNullValue())); Message received = subscriber.receive(getReceiveTimeout()); session.commit(); assertThat("Failed to receive published message", received, is(notNullValue())); assertThat("Message is not Text message", received, is(instanceOf(TextMessage.class))); assertThat("Unexpected text", ((TextMessage) received).getText(), is(equalTo("B"))); assertThat("Unexpected index", received.getIntProperty("ID"), is(equalTo(index))); session.close(); } finally { connection.close(); } }
Example 20
Source File: ObjectMessageDeliveryTest.java From activemq-artemis with Apache License 2.0 | 2 votes |
/** * */ @Test public void testTopic() throws Exception { TopicConnection conn = getTopicConnectionFactory().createTopicConnection(); try { TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher publisher = s.createPublisher(ActiveMQServerTestCase.topic1); TopicSubscriber sub = s.createSubscriber(ActiveMQServerTestCase.topic1); conn.start(); // Create 3 object messages with different bodies TestObject to1 = new TestObject(); to1.text = "hello1"; TestObject to2 = new TestObject(); to1.text = "hello2"; TestObject to3 = new TestObject(); to1.text = "hello3"; ObjectMessage om1 = s.createObjectMessage(); om1.setObject(to1); ObjectMessage om2 = s.createObjectMessage(); om2.setObject(to2); ObjectMessage om3 = s.createObjectMessage(); om3.setObject(to3); // send to topic publisher.send(om1); publisher.send(om2); publisher.send(om3); ObjectMessage rm1 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); ObjectMessage rm2 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); ObjectMessage rm3 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); ProxyAssertSupport.assertNotNull(rm1); TestObject ro1 = (TestObject) rm1.getObject(); ProxyAssertSupport.assertEquals(to1.text, ro1.text); ProxyAssertSupport.assertNotNull(rm1); TestObject ro2 = (TestObject) rm2.getObject(); ProxyAssertSupport.assertEquals(to2.text, ro2.text); ProxyAssertSupport.assertNotNull(rm2); TestObject ro3 = (TestObject) rm3.getObject(); ProxyAssertSupport.assertEquals(to3.text, ro3.text); } finally { if (conn != null) { conn.close(); } } }