Search in sources :

Example 1 with ConsumerEvent

use of org.apache.activemq.advisory.ConsumerEvent in project pinpoint by naver.

the class MessageConsumerBuilder method build.

public MessageConsumer build() throws Exception {
    MessageConsumer consumer = null;
    if (waitTillStarted) {
        ConsumerEventSource consumerEventSource = new ConsumerEventSource(session.getConnection(), destination);
        final CountDownLatch latch = new CountDownLatch(1);
        consumerEventSource.setConsumerListener(new ConsumerListener() {

            @Override
            public void onConsumerEvent(ConsumerEvent event) {
                latch.countDown();
            }
        });
        try {
            consumerEventSource.start();
            consumer = this.session.createConsumer(this.destination);
            if (!latch.await(5L, TimeUnit.SECONDS)) {
                throw new TimeoutException("Timed out waiting for MessageConsumer start event.");
            }
        } finally {
            consumerEventSource.stop();
        }
    } else {
        consumer = this.session.createConsumer(this.destination);
    }
    if (this.messageListener != null) {
        consumer.setMessageListener(this.messageListener);
    }
    return consumer;
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ConsumerEventSource(org.apache.activemq.advisory.ConsumerEventSource) ConsumerEvent(org.apache.activemq.advisory.ConsumerEvent) ConsumerListener(org.apache.activemq.advisory.ConsumerListener) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 MessageConsumer (javax.jms.MessageConsumer)1 ConsumerEvent (org.apache.activemq.advisory.ConsumerEvent)1 ConsumerEventSource (org.apache.activemq.advisory.ConsumerEventSource)1 ConsumerListener (org.apache.activemq.advisory.ConsumerListener)1