modules/tests/test-integration/src/test/java/org/ballerinalang/test/service/jms/sample/JMSServiceSampleTestCase.java
/**
     * To receive a message from a topic.
     *
     * @throws JMSException         JMS Exception
     * @throws InterruptedException Interrupted exception while waiting in between messages
     */
To receive a message from a topic.
@throws JMSException         JMS Exception
@throws InterruptedException Interrupted exception while waiting in between messages
To receive a message from a topic . @throws JMSException JMS Exception @throws InterruptedException Interrupted exception while waiting in between messages
private void receiveMessagesFromTopic(String topicName) throws JMSException, InterruptedException {
        ConnectionFactory connectionFactory = JMSBroker.getConnectionFactory();
        TopicConnection queueConn = (TopicConnection) connectionFactory.createConnection();
        queueConn.start();
        TopicSession queueSession = queueConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic destination = queueSession.createTopic(topicName);
        TopicSubscriber queueReceiver = queueSession.createSubscriber(destination);
        queueReceiver.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                if (message instanceof MapMessage) {
                    try {
                        int value = Integer.parseInt(((MapMessage) message).getString(mapProperty));
                        Assert.assertTrue(value >= 0 && value < 10, value + " is not within the expected value");
                    } catch (JMSException e) {
                        logger.error("JMS Exception occured while getting the map message", e);
                    }
                    messageCount++;
                }
            }
        });
    }
private void receiveMessagesFromTopic ( String topicName ) throws JMSException , InterruptedException { ConnectionFactory connectionFactory = JMSBroker . getConnectionFactory ( ) ; TopicConnection queueConn = ( TopicConnection ) connectionFactory . createConnection ( ) ; queueConn . start ( ) ; TopicSession queueSession = queueConn . createTopicSession ( false , Session . AUTO_ACKNOWLEDGE ) ; Topic destination = queueSession . createTopic ( topicName ) ; TopicSubscriber queueReceiver = queueSession . createSubscriber ( destination ) ; queueReceiver . setMessageListener ( new MessageListener ( ) { @ Override public void onMessage ( Message message ) { if ( message instanceof MapMessage ) { try { int value = Integer . parseInt ( ( ( MapMessage ) message ) . getString ( mapProperty ) ) ; Assert . assertTrue ( value >= 0 && value < 10 , value + " is not within the expected value" ) ; } catch ( JMSException e ) { logger . error ( "JMS Exception occured while getting the map message" , e ) ; } messageCount ++ ; } } } ) ; }
To receive a message from a topic.
To receive a message from a topic .