Rabbitmq 在调用Spring Amqp的OnMessageIf MessageListener之前添加默认方法

Rabbitmq 在调用Spring Amqp的OnMessageIf MessageListener之前添加默认方法,rabbitmq,spring-amqp,spring-rabbit,Rabbitmq,Spring Amqp,Spring Rabbit,我需要添加一些默认功能,在调用实现类的onMessageFunctionality之前,这些功能将从SpringAMQP中的消息头中选取一些值 乙二醇 从上面的例子中,我需要在调用onMessage之前使用Message对象调用一些定制的功能 在SpringAmqp中是否有任何优雅的方法可以实现同样的效果?您可以在侦听器周围创建一个简单的包装器类 public void onMessage(Message message) { // process myListener.onMe

我需要添加一些默认功能,在调用实现类的onMessageFunctionality之前,这些功能将从SpringAMQP中的消息头中选取一些值

乙二醇

从上面的例子中,我需要在调用onMessage之前使用Message对象调用一些定制的功能


在SpringAmqp中是否有任何优雅的方法可以实现同样的效果?您可以在侦听器周围创建一个简单的包装器类

public void onMessage(Message message) {
    // process
    myListener.onMessage(message)
}
或者,侦听器容器有一个属性
afterReceivePostProcessors
,正是因为这个原因

/**
 * Set {@link MessagePostProcessor}s that will be applied after message reception, before
 * invoking the {@link MessageListener}. Often used to decompress data.  Processors are invoked in order,
 * depending on {@code PriorityOrder}, {@code Order} and finally unordered.
 * @param afterReceivePostProcessors the post processor.
 * @since 1.4.2
 */
public void setAfterReceivePostProcessors(MessagePostProcessor... afterReceivePostProcessors) { ... }

我不明白这个问题,或者是背后的原因。。。如果您想在收到邮件之前更改邮件,请在发送之前进行更改。或者您可能只是想使用头交换之类的东西?要求是在消息到达消息之前在侦听器端执行任何业务操作。例如,从生产者端设置消息头中的值,即thread name=t1,在监听器端,我将检索该值,并对该t1执行任何通用操作。对于其他消息,threadname的值可以是t2等。但只有在收到消息(或我丢失了某些内容)时才会调用
onMessage
/**
 * Set {@link MessagePostProcessor}s that will be applied after message reception, before
 * invoking the {@link MessageListener}. Often used to decompress data.  Processors are invoked in order,
 * depending on {@code PriorityOrder}, {@code Order} and finally unordered.
 * @param afterReceivePostProcessors the post processor.
 * @since 1.4.2
 */
public void setAfterReceivePostProcessors(MessagePostProcessor... afterReceivePostProcessors) { ... }