SpringAmqp 拦截器中的处理程序方法名称

Handler method name in SpringAmqp interceptors

我将 spring amqp 与 multi-method 侦听器一起使用,如下所示:

@RabbitListener(queues = PLATFORM_COMMAND_QUEUE)
@Component
public class PlatformListener {

    @RabbitHandler
    public Response<GetAllPlatformsResponse> getAllPlatforms(GetAllPlatforms command) {
        ...
        return Response.ok(GetAllPlatformsResponse.create(allPlatforms));
    }

    @RabbitHandler
    public Response<PlatformResponse> getPlatform(GetPlatformCommand command) {
        ...        
        return Response.ok(platformService.getPlatform(command));
    }
}

我想为所有响应消息添加特定的 header 和处理程序名称(getAllPlatforms、getPlatform)。为此,我尝试添加 setAfterReceivePostProcessors 和 setBeforeSendReplyPostProcessors,但它们不提供有关处理程序方法的任何信息。

 factory.setBeforeSendReplyPostProcessors(message -> {
     Method targetMethod = message.getMessageProperties().getTargetMethod();
     assert targetMethod == null;
     return message;
 });

如何获取方法名称并将其添加到回复消息中header?

目前不可能;正如 javadocs 所述,属性 仅针对方法级别 @RabbitListener.

填充
/**
 * The target method when using a method-level {@code @RabbitListener}.
 * @return the method.
 * @since 1.6
 */
public Method getTargetMethod() {
    return this.targetMethod;
}

考虑到多年来架构的一些变化,我认为现在应该也可以为 class 级别的听众填充它。请open a new feature suggestion,我会看看添加它。