如何将响应式拦截器添加到Spring Boot注释控制器中?



我已经在CLIENT上使用rsocket-micrometer设置了rsocket度量在RSocketConnector上配置拦截器,像这样(Kotlin):

rSocketReqesterBuilder.rsocketConnector { configureConnector(it) }
// ...
private fun configureConnector(rSocketConnector: RSocketConnector) {
rSocketConnector.interceptors { iRegistry ->
// This gives us the rsocket.* counter metrics, like rsocket.frame
iRegistry.forResponder(MicrometerRSocketInterceptor(registry, *localTags.toArray()))
iRegistry.forRequester(MicrometerRSocketInterceptor(registry, *localTags.toArray()))
iRegistry.forConnection(MicrometerDuplexConnectionInterceptor(registry, *localTags.toArray()))
}
}

但是在SERVER这边,我使用一个带注释的(@MessageMapping) Spring Boot RSocket控制器,像这样(Java):

@MessageMapping("replace-channel-controller")
public Flux<TransformResponse> replace(Flux<String> texts) ...
在这里,我没有显式地控制连接器。
如何在服务器端添加拦截器?
@Configuration
public class RSocketConfig implements RSocketServerCustomizer {
private final MeterRegistry registry;
public RSocketConfig(MeterRegistry registry) {
this.registry = registry;
}
@Override
public void customize(RSocketServer rSocketServer) {
rSocketServer.interceptors(
iRegistry -> {
log.info("Adding RSocket interceptors...");
iRegistry.forResponder(new MicrometerRSocketInterceptor(registry, tags));
iRegistry.forRequester(new MicrometerRSocketInterceptor(registry, tags));
iRegistry.forConnection(new MicrometerDuplexConnectionInterceptor(registry, tags));
}
);
}
}

相关内容

  • 没有找到相关文章

最新更新