我有2个服务生产者和消费者. 在服务使用者中,我有多个位置使用SecurityConextHolder来获取当前用户. 然后,我想在发送消息时将用户ID从Producer传递给Consumer.
我的回答是:https://stackoverflow.com/a/49957948/6484502 但我不知道如何从建议中获得信息?
你能提供一个这个建议的例子吗?
我有2个服务生产者和消费者. 在服务使用者中,我有多个位置使用SecurityConextHolder来获取当前用户. 然后,我想在发送消息时将用户ID从Producer传递给Consumer.
我的回答是:https://stackoverflow.com/a/49957948/6484502 但我不知道如何从建议中获得信息?
你能提供一个这个建议的例子吗?
你需要实施一个org.aopalliance.intercept.MethodInterceptor
.AMQP消息是MethodInvocation.getArguments()
的第二个自变量.你把它换成org.springframework.amqp.core.Message
,坐userId
,然后在invocation.proceed()
之前打ctx.setAuthentication()
.