Search in sources :

Example 1 with Consume

use of org.apache.camel.Consume in project camel by apache.

the class AnnotatedConsumeImpl method handleTitle.

@Consume(uri = "seda:book")
public void handleTitle(String title) {
    Transactional tx = this.getClass().getAnnotation(Transactional.class);
    if (tx == null) {
        throw new IllegalStateException("Spring annotation-driven should have instrumented this class as @Transactional");
    }
    if (!"NEVER".equals(tx.propagation().name())) {
        throw new IllegalStateException("Should be NEVER propagation");
    }
    if (!tx.readOnly()) {
        throw new IllegalStateException("Should be read only");
    }
    if (!title.contains("in Action")) {
        throw new IllegalArgumentException("Not a book title we like");
    }
    producer.sendBody(title);
}
Also used : Transactional(org.springframework.transaction.annotation.Transactional) Consume(org.apache.camel.Consume)

Example 2 with Consume

use of org.apache.camel.Consume in project camel by apache.

the class CamelPostProcessorHelper method consumerInjection.

public void consumerInjection(Method method, Object bean, String beanName) {
    Consume consume = method.getAnnotation(Consume.class);
    if (consume != null && matchContext(consume.context())) {
        LOG.debug("Creating a consumer for: " + consume);
        subscribeMethod(method, bean, beanName, consume.uri(), consume.ref(), consume.property());
    }
}
Also used : Consume(org.apache.camel.Consume)

Example 3 with Consume

use of org.apache.camel.Consume in project opennms by OpenNMS.

the class DispatcherWhiteboard method dispatch.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Consume(property = "endpointUri")
public void dispatch(final Object message) throws NoSuchMethodException, SecurityException {
    LOG.debug("dispatch: {}", message);
    if (m_tracker == null) {
        m_tracker = new ServiceTracker(m_context, m_serviceClass, null);
        m_tracker.open();
    }
    if (m_method == null) {
        m_method = m_serviceClass.getMethod(m_methodName, m_messageClass);
    }
    try {
        Object[] services = m_tracker.getServices();
        if (services != null && services.length > 0) {
            for (Object service : m_tracker.getServices()) {
                m_method.invoke(service, message);
            }
        } else {
            // in case there is no dispatcher registered, let the user know.
            LOG.warn("No dispatcher for message found. ServiceClass: {}, ServiceMethod: {}", m_serviceClass, m_methodName);
        }
    } catch (Throwable e) {
        // If anything goes wrong, log an error message
        // TODO: Use a dead-letter channel?
        LOG.warn("Message dispatch failed: " + e.getMessage(), e);
    }
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) Consume(org.apache.camel.Consume)

Aggregations

Consume (org.apache.camel.Consume)3 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1 Transactional (org.springframework.transaction.annotation.Transactional)1