All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.axonframework.spring.config.MessageHandlerSubscriberDefinitionRegistrar Maven / Gradle / Ivy

Go to download

Module providing Spring specific helper functionality to ease configuration / set-up of an Axon application, as well as some Spring specific infrastructure components.

There is a newer version: 4.10.3
Show newest version
package org.axonframework.spring.config;

import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.MultiValueMap;

/**
 * @author Allard Buijze
 */
public class MessageHandlerSubscriberDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        MultiValueMap attributes = metadata
                .getAllAnnotationAttributes(EnableHandlerSubscription.class.getName());

        if (Boolean.TRUE.equals(attributes.getFirst("subscribeEventProcessors"))
                || Boolean.TRUE.equals(attributes.getFirst("subscribeEventListeners"))) {
            final GenericBeanDefinition definition = new GenericBeanDefinition();
            //definition.setBeanClass(EventListenerSubscriber.class);
            final Object eventBusRef = attributes.getFirst("eventBus");
            if (!"".equals(eventBusRef)) {
                definition.getPropertyValues().add("eventBus",
                                                   new RuntimeBeanReference((String) eventBusRef));
            }
            registry.registerBeanDefinition("EventListenerSubscriber", definition);
        }

        if (Boolean.TRUE.equals(attributes.getFirst("subscribeCommandHandlers"))) {
            final GenericBeanDefinition definition = new GenericBeanDefinition();
            definition.setBeanClass(CommandHandlerSubscriber.class);
            registry.registerBeanDefinition("CommandHandlerSubscriber", definition);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy