Example usage for javax.jms QueueReceiver receive

List of usage examples for javax.jms QueueReceiver receive

Introduction

In this page you can find the example usage for javax.jms QueueReceiver receive.

Prototype


Message receive() throws JMSException;

Source Link

Document

Receives the next message produced for this message consumer.

Usage

From source file:org.panksdmz.jms.tibco.MessageRecieverBean.java

public void recieve() {
    try {//from   w  w w  .  j a  v a2s  . c o m
        QueueConnection connection = connectionFactory.createQueueConnection();
        QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(this.recieveQueueName);
        QueueReceiver receiver = session.createReceiver(queue);
        connection.start();

        Message receive = receiver.receive();

        System.out.println(receive);

    } catch (JMSException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.flink.streaming.connectors.jms.JmsQueueSource.java

@Override
public void run(final SourceContext<T> context) throws Exception {
    QueueSession session = null;/*from www .  ja v  a  2s .c  om*/
    QueueReceiver consumer = null;

    try {
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        consumer = session.createReceiver(destination, messageSelector);

        connection.start();

        while (isRunning) {
            context.collect(convert(consumer.receive()));
        }
    } catch (JMSException e) {
        logger.error("Error receiving message from [{}]: {}", destination.getQueueName(),
                e.getLocalizedMessage());
        throw new UncategorizedJmsException(e);
    } finally {
        JmsUtils.closeMessageConsumer(consumer);
        JmsUtils.closeSession(session);
    }
}