0

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) ...

在这里,我没有明确控制连接器。
如何在服务器端添加拦截器?

4

1 回答 1

0
@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));
                }
        );
    }
}
于 2021-11-10T22:09:35.773 回答