Axon EventHandler不接收事件

问题描述 投票:1回答:1

我需要有关正确配置Axon应用程序的帮助,否则我对axon的理解是错误的。我有两个聚合:

  • “ FileStore”,将存储有关索引文件的信息
  • “ DirectoryLister”,它为其索引的每个文件发送事件。

我遇到的问题是,“ DirectoryLister”使用]发送事件>

AggregateLifecycle.apply(new IndexedFileEvent(...)); 

并且在“ DirectoryLister”内部,我能够在EventSourcingHandler中捕获事件。但是在“ FileStore”内部,事件处理程序不响应。我验证了该事件已在事件总线上发布。我认为,我需要使用“ AnnotationEventListenerAdapter”以某种方式使FileStore在事件总线上进行侦听,但是如果没有关于它的工作原理的弹簧,我将找不到一个示例。

我在不使用Spring的情况下使用Axon 3.4.3,并按如下所示配置应用程序:

    Configurer configer = DefaultConfigurer.defaultConfiguration();
    configer.configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine());
    // configure two Aggregates
    configer.configureAggregate(FileStore.class);
    configer.configureAggregate(DirectoryLister.class);

    // how can I register FileStore as an eventListener? Using AnnotationEventListenerAdapter?

    Configuration config = configer.buildConfiguration();

    // verify that event is published on the event bus
    config.eventBus().subscribe(l -> l.forEach( e -> System.out.println(e.toString())));
    config.start();

FileStore类看起来像这样:

public class FileStore {
    @AggregateIdentifier String id; 

    public FileStore() { }

    @CommandHandler public FileStore(CreateFileStoreCommand command) {
        AggregateLifecycle.apply(new FileStoreCreatedEvent(command.getId()));
    }

    @EventSourcingHandler public void on(FileStoreCreatedEvent event) {
        id = event.getId();
    }

    @EventSourcingHandler public void on(IndexedFileEvent event) {
        System.out.println(event.getParentPath() + "//" + event.getName() + "  " + event.getSize().toString());
    }

“ DirectoryLister”类看起来像这样:

  public class DirectoryLister {
    @AggregateIdentifier String id; 

    protected  DirectoryLister() { }

    @CommandHandler public DirectoryLister(CreateListerCommand cmd) {
        AggregateLifecycle.apply(new CreateListerEvent(cmd.getId()));   
    }

    @CommandHandler public void handleCommand(IndexDirectoryCommand cmd) throws IOException {
         FileVisitor<Path> fv = new SimpleFileVisitor<Path>() {
              @Override
              public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                // this is where the event is sent!
                AggregateLifecycle.apply(new IndexedFileEvent(file.getFileName().toString(),file.getParent().toString(), attrs.size())); 
                return FileVisitResult.CONTINUE;
              }
            };

          Files.walkFileTree(cmd.getPath(), fv);
    }

    @EventSourcingHandler public void on (CreateListerEvent event) { id = event.getId(); }

    // This handler is invoked. 
    @EventSourcingHandler public void on(IndexedFileEvent event) {
        System.out.println(event.getParentPath() + "//" + event.getName() + "  " + event.getSize().toString());
    }
}

我需要有关正确配置Axon应用程序的帮助,否则我对axon的理解是错误的。我有两个聚合:“ FileStore”,它将存储有关索引文件的信息“ ...

java event-bus axon
1个回答
1
投票

如果我正确地遵循,您正在尝试处理从聚合DirectoryLister中发布的事件,在聚合FileStore中是正确的吗?

© www.soinside.com 2019 - 2024. All rights reserved.