RGH-83: Allow binders to add interceptors

Resolves https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/83

The RabbitMQ binder needs to add an interceptor to evaluate expressions (if they
include `payload`) before the payload is serialized.

Add a hook to allow the binder to post-process the message channel.

Resolves #1134
This commit is contained in:
Gary Russell
2017-11-10 13:36:09 -05:00
committed by Oleg Zhurakousky
parent 61240fd0fa
commit b865f3cbe9
2 changed files with 13 additions and 2 deletions

View File

@@ -97,8 +97,8 @@ public abstract class AbstractBinder<T, C extends ConsumerProperties, P extends
return this.applicationContext.getBeanFactory();
}
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
this.evaluationContext = evaluationContext;
protected EvaluationContext getEvaluationContext() {
return this.evaluationContext;
}
@Override

View File

@@ -138,6 +138,7 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
if (producerMessageHandler instanceof Lifecycle) {
((Lifecycle) producerMessageHandler).start();
}
postProcessOutputChannel(outputChannel, producerProperties);
((SubscribableChannel) outputChannel).subscribe(
new SendingHandler(producerMessageHandler, HeaderMode.embeddedHeaders
.equals(producerProperties.getHeaderMode()), this.headersToEmbed,
@@ -163,6 +164,16 @@ public abstract class AbstractMessageChannelBinder<C extends ConsumerProperties,
};
}
/**
* Allows subclasses to perform post processing on the channel - for example to
* add more interceptors.
* @param outputChannel the channel.
* @param producerProperties the producer properties.
*/
protected void postProcessOutputChannel(MessageChannel outputChannel, P producerProperties) {
// default no-op
}
/**
* Creates a {@link MessageHandler} with the ability to send data to the target
* middleware. If the returned instance is also a {@link Lifecycle}, it will be