gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:28:31 25 4
gpt4 key购买 nike

我将 spring amqp 与多方法监听器一起使用,如下所示:

@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));
}
}

我想为所有响应消息添加带有处理程序名称(getAllPlatforms、getPlatform)的特定 header 。为此,我尝试添加 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;
}

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

关于java - SpringAmqp 拦截器中的处理程序方法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59283838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com