Search in sources :

Example 96 with MessageConsumer

use of javax.jms.MessageConsumer in project sling by apache.

the class ActiveMQConnectionFactoryServiceTest method testGetConnectionFactory.

@Test
public void testGetConnectionFactory() throws Exception {
    LOGGER.info("Starting test");
    ActiveMQConnectionFactoryService cfs = ActiveMQConnectionFactoryServiceTest.activate();
    ConnectionFactory cf = cfs.getConnectionFactory();
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Topic t = session.createTopic("testTopic");
    MessageConsumer consumer = session.createConsumer(t);
    LOGGER.info("Starting connection");
    connection.start();
    LOGGER.info("Connection started.. sending message");
    session.createProducer(t).send(session.createTextMessage("testing with a message"));
    session.commit();
    LOGGER.info("Message sent ... receiving message");
    Message m = consumer.receive();
    LOGGER.info("Message received");
    assertTrue(m instanceof TextMessage);
    assertEquals("testing with a message", ((TextMessage) m).getText());
    session.close();
    connection.stop();
    deactivate(cfs);
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 97 with MessageConsumer

use of javax.jms.MessageConsumer in project hive by apache.

the class TestNotificationListener method setUp.

@Before
public void setUp() throws Exception {
    System.setProperty("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    System.setProperty("java.naming.provider.url", "vm://localhost?broker.persistent=false");
    ConnectionFactory connFac = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    Connection conn = connFac.createConnection();
    conn.start();
    // We want message to be sent when session commits, thus we run in
    // transacted mode.
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX);
    MessageConsumer consumer1 = session.createConsumer(hcatTopic);
    consumer1.setMessageListener(this);
    Destination tblTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb.mytbl");
    MessageConsumer consumer2 = session.createConsumer(tblTopic);
    consumer2.setMessageListener(this);
    Destination dbTopic = session.createTopic(HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX + ".mydb");
    MessageConsumer consumer3 = session.createConsumer(dbTopic);
    consumer3.setMessageListener(this);
    setUpHiveConf();
    hiveConf.set(ConfVars.METASTORE_EVENT_LISTENERS.varname, NotificationListener.class.getName());
    hiveConf.setVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_MANAGER, "org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory");
    SessionState.start(new CliSessionState(hiveConf));
    driver = DriverFactory.newDriver(hiveConf);
    client = new HiveMetaStoreClient(hiveConf);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) HiveMetaStoreClient(org.apache.hadoop.hive.metastore.HiveMetaStoreClient) Connection(javax.jms.Connection) CliSessionState(org.apache.hadoop.hive.cli.CliSessionState) Session(javax.jms.Session) Before(org.junit.Before)

Example 98 with MessageConsumer

use of javax.jms.MessageConsumer in project gocd by gocd.

the class ActiveMqMessagingService method addQueueListener.

public JMSMessageListenerAdapter addQueueListener(String queueName, final GoMessageListener listener) {
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
        return JMSMessageListenerAdapter.startListening(consumer, listener, daemonThreadStatsCollector);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 99 with MessageConsumer

use of javax.jms.MessageConsumer in project cxf by apache.

the class MessageListenerTest method drainQueue.

protected void drainQueue(Connection connection, Queue dest) throws JMSException, InterruptedException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(dest);
    while (consumer.receiveNoWait() != null) {
        System.out.println("Consuming old message");
    }
    consumer.close();
    session.close();
    assertNumMessagesInQueue("", connection, dest, 0, 0);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Session(javax.jms.Session)

Example 100 with MessageConsumer

use of javax.jms.MessageConsumer in project cxf by apache.

the class TestReceiver method receiveAndRespond.

private void receiveAndRespond() {
    try (ResourceCloser closer = new ResourceCloser()) {
        Connection connection = closer.register(connectionFactory.createConnection());
        connection.start();
        Session session = closer.register(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
        MessageConsumer consumer = closer.register(session.createConsumer(session.createQueue(receiveQueueName)));
        final javax.jms.Message inMessage = consumer.receive(10000);
        if (inMessage == null) {
            // System.out.println("TestReceiver timed out");
            throw new RuntimeException("No message received on destination " + receiveQueueName);
        }
        requestMessageId = inMessage.getJMSMessageID();
        // System.out.println("Received message " + requestMessageId);
        final TextMessage replyMessage = session.createTextMessage("Result");
        String correlationId = (forceMessageIdAsCorrelationId || inMessage.getJMSCorrelationID() == null) ? inMessage.getJMSMessageID() : inMessage.getJMSCorrelationID();
        replyMessage.setJMSCorrelationID(correlationId);
        Destination replyDest = staticReplyQueue != null ? session.createQueue(staticReplyQueue) : inMessage.getJMSReplyTo();
        if (replyDest != null) {
            final MessageProducer producer = closer.register(session.createProducer(replyDest));
            // System.out.println("Sending reply with correlation id " + correlationId + " to " + replyDest);
            producer.send(replyMessage);
        }
    } catch (Throwable e) {
        ex = e;
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

MessageConsumer (javax.jms.MessageConsumer)107 Session (javax.jms.Session)64 Message (javax.jms.Message)50 MessageProducer (javax.jms.MessageProducer)49 Connection (javax.jms.Connection)47 TextMessage (javax.jms.TextMessage)45 Test (org.junit.Test)45 Destination (javax.jms.Destination)24 JMSException (javax.jms.JMSException)23 ConnectionFactory (javax.jms.ConnectionFactory)15 TemporaryQueue (javax.jms.TemporaryQueue)9 Queue (javax.jms.Queue)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 ObjectMessage (javax.jms.ObjectMessage)7 MessageListener (javax.jms.MessageListener)6 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)5 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)4 HornetQMixIn (org.switchyard.component.test.mixins.hornetq.HornetQMixIn)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3