相关疑难解决方法(0)

用反应堆开火就忘

我的 Spring boot 应用程序中有一个如下所示的方法。

public Flux<Data> search(SearchRequest request) {
  Flux<Data> result = searchService.search(request);//this returns Flux<Data>
  Mono<List<Data>> listOfData = result.collectList();
//  doThisAsync() // here I want to pass this list and run some processing on it
// the processing should happen async and the search method should return immediately.
  return result;
}

//this method uses the complete List<Data> returned by above method
public void doThisAsync(List<Data> data) {
  //do some processing here
}

Run Code Online (Sandbox Code Playgroud)

目前,我正在使用带@Async注释的服务类doThisAsync,但不知道如何传递List<Data>,因为我不想调用block. …

spring reactive-programming spring-boot project-reactor spring-webflux

3
推荐指数
1
解决办法
4432
查看次数

webflux:内部事件总线和异步、Loosley 耦合的事件侦听器

如何实现内部事件总线以在 webflux spring 堆栈中执行异步操作?

我想要一个服务发出一个事件:

@Service
class FeedServiceImpl(/*...dependencies...*/) : FeedService {
  override suspend fun deleteEntry(entryId: Long) {
    entryRepository.deleteById(entryId)
    publishEvent(
      FeedEntryDeletedEvent(
        timestamp = time.utcMillis(),
        entryId = entryId,
      )
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

发布者服务不知道的不同组件应该能够决定对该事件做出反应。

@Service
class CommentServiceImpl(/*...dependencies...*/): CommentService {
  override suspend fun onDeleteEntry(event: FeedEntryDeletedEvent) {
    // do stuff
  }
}
Run Code Online (Sandbox Code Playgroud)

在 MVC 应用程序中,我将使用在处理程序 ( ) 上ApplicationEventPublisher发布事件 ( publishEvent) 和@EventListener+ 。@AsynconDeleteEntry

反应式堆栈中的等效项是什么?

我考虑的另一个选择是运行嵌入式消息服务,因为这应该意味着异步语义。但这对于一个简单的场景来说感觉是很大的开销。


我找到了这些SO线程

但他们不回答这种情况,因为他们假设发布者知道侦听器。但我需要松散耦合。

我还发现了这些春季问题 …

spring spring-boot spring-webflux

3
推荐指数
1
解决办法
2438
查看次数