Search in sources :

Example 1 with ConsumerEventSource

use of org.apache.activemq.advisory.ConsumerEventSource 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)

Example 2 with ConsumerEventSource

use of org.apache.activemq.advisory.ConsumerEventSource in project cxf by apache.

the class JmsPublisher method start.

@Override
protected void start() throws PublisherRegistrationFailedFault {
    if (demand) {
        try {
            producers = new HashMap<>();
            advisories = new ArrayList<>();
            for (TopicExpressionType topic : this.topic) {
                ConsumerEventSource advisory = new ConsumerEventSource(connection, topicConverter.toActiveMQTopic(topic));
                advisory.setConsumerListener(this);
                advisory.start();
                advisories.add(advisory);
            }
        } catch (Exception e) {
            PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType();
            throw new PublisherRegistrationFailedFault("Error starting demand-based publisher", fault, e);
        }
    }
}
Also used : PublisherRegistrationFailedFaultType(org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType) TopicExpressionType(org.oasis_open.docs.wsn.b_2.TopicExpressionType) ConsumerEventSource(org.apache.activemq.advisory.ConsumerEventSource) PublisherRegistrationFailedFault(org.oasis_open.docs.wsn.brw_2.PublisherRegistrationFailedFault) JMSException(javax.jms.JMSException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

ConsumerEventSource (org.apache.activemq.advisory.ConsumerEventSource)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 JMSException (javax.jms.JMSException)1 MessageConsumer (javax.jms.MessageConsumer)1 JAXBException (javax.xml.bind.JAXBException)1 ConsumerEvent (org.apache.activemq.advisory.ConsumerEvent)1 ConsumerListener (org.apache.activemq.advisory.ConsumerListener)1 TopicExpressionType (org.oasis_open.docs.wsn.b_2.TopicExpressionType)1 PublisherRegistrationFailedFaultType (org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType)1 PublisherRegistrationFailedFault (org.oasis_open.docs.wsn.brw_2.PublisherRegistrationFailedFault)1