Java源码示例:org.axonframework.eventhandling.EventBus

示例1
/**
 * Scans for an event bus producer.
 *
 * @param processProducer process producer event.
 */
<T> void processEventBusProducer(
        @Observes final ProcessProducer<T, EventBus> processProducer) {
    // TODO Handle multiple producer definitions.

    logger.debug("Producer for event bus found: {}.", processProducer.getProducer());

    this.eventBusProducer = processProducer.getProducer();
}
 
示例2
@Bean
public EventBus eventBus() {
    return mock(EventBus.class);
}
 
示例3
public BankAccountCommandHandler(Repository<BankAccount> repository, EventBus eventBus) {
    this.repository = repository;
    this.eventBus = eventBus;
}
 
示例4
public static void main(String[] args) {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
                SchedulerConfig.class,
                RabbitMQLocalConfig.class,
                AxonCQRSConfig.class,
                ToDoConfig.class
        );

        try {
            // let's start with the Command Bus
//        CommandBus commandBus = new SimpleCommandBus();
            CommandBus commandBus = ctx.getBean(CommandBus.class);

            // the CommandGateway provides a friendlier API
//        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);
            CommandGateway commandGateway = ctx.getBean(CommandGateway.class);

            // we'll store Events on the FileSystem, in the "events/" folder
//        EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));
//        EventStore eventStore = ctx.getBean(EventStore.class);

            // a Simple Event Bus will do
//        EventBus eventBus = new SimpleEventBus();
            EventBus eventBus = ctx.getBean(EventBus.class);

            // we need to configure the repository
//        EventSourcingRepository repository = new EventSourcingRepository(ToDoItem.class, eventStore);
//        repository.setEventBus(eventBus);
            EventSourcingRepository repository = ctx.getBean("toDoItemRepository", EventSourcingRepository.class);

            // Axon needs to know that our ToDoItem Aggregate can handle commands
//            AggregateAnnotationCommandHandler.subscribe(ToDoItem.class, repository, commandBus);
//            AnnotationEventListenerAdapter.subscribe(new ToDoEventHandler(), eventBus);

            // and let's send some Commands on the CommandBus.
            final ToDoIdentifier id = new ToDoIdentifier();
            commandGateway.send(new CreateToDoItemCommand(id, "Need to do this", "user"));
            commandGateway.send(new MarkToDoItemAsCompleteCommand(id, "user"));
        } finally {
            ctx.destroy();
        }

    }
 
示例5
@Override
    public void init(ServletConfig config) throws ServletException {
       super.init(config);

       ac = new ClassPathXmlApplicationContext("/axon-db2-configuration.xml");
       
       logger.debug("sono nella init della servlet");
       
       // we get the event bus from the application context
       EventBus eventBus = ac.getBean(EventBus.class);
//       eventBus.subscribe(eventListener);
	      
    }