diff --git a/src/docbkx/message-publishing.xml b/src/docbkx/message-publishing.xml index c75bcf9b12..ebacbcd0a0 100644 --- a/src/docbkx/message-publishing.xml +++ b/src/docbkx/message-publishing.xml @@ -121,10 +121,46 @@ public String argumentAsPayload(@Payload String fname, @Header String lname) { <si:annotation-config default-publisher-channel="defaultChannel"/> + + + Similar to other Spring annotations (e.g., @Controller), @Publisher is a meta-annotation, which means you can define your own annotations + that will be treated as @Publisher + +Here we defined @Audit annotation which itself is a @Publisher. Also note that you can define channel +attribute on the meta-annotation thus encapsulating the behavior of where messages will be sent inside of this annotation. + +Now you can annotate any method: + + +In the above example every invocation of test() method will result in Message with payload which is the return value of the method +invocation to be sent to auditChannel + +You can also annotate the class which would mean that the properties of this annotation will be applied on every public method of this class + + + +
- XML-based approach via <publisher> element + XML-based approach via <publishing-interceptor> element The XML-based approach allows you to configure the same AOP-based Message Publishing functionality with simple namespace-based configuration of a MessagePublishingInterceptor. @@ -145,22 +181,22 @@ public String argumentAsPayload(@Payload String fname, @Header String lname) { - -<beans:bean id="testBean" class="org.foo.bar.TestBean" /> -<aop:config> - <aop:advisor advice-ref="interceptor" pointcut="bean(testBean)" /> -</aop:config> - -<publishing-interceptor id="interceptor" default-channel="defaultChannel"> - <method pattern="echo" payload="'Echoing: ' + #return" headers="foo='bar'" channel="echoChannel"/> - <method pattern="echoDef*" payload="#return"/> - <method pattern="foo*"/> -</publishing-interceptor> - + + + + + +
+ + +
+ + +]]> - As you can see the <publisher> element expects the same variables as the - PublisherAnnotationAdvisor and also utilizes the power of the Spring 3.0 Expression Language. + As you can see the <publishing-interceptor> configuration look rather similar to Annotation-based approach + and it also utilizes the power of the Spring 3.0 Expression Language. In the above example the execution of the echo method of a testBean will @@ -169,15 +205,31 @@ public String argumentAsPayload(@Payload String fname, @Header String lname) { The Message payload will be of type String and value of "Echoing: [value]" where value is the value returned by an executed method. - + - The Message headers will contain the key "foo" with a value of "bar". + The Message will have header with the key "foo" value "bar". The Message will be sent to echoChannel. + + + The second method is very siumilar to the first. Here every method that begings with 'repl' will rander a Message with teh following structure: + + + The Message payload will be the same as in the above sample + + + The Message will have header with the key "foo" and value that is the result of the SpEL expression 'bar'.toUpperCase() . + + + The Message will be sent to echoChannel. + + + + The second method, mapping the execution of any method that begins with echoDef of testBean, will produce a Message with the following structure. @@ -191,14 +243,11 @@ public String argumentAsPayload(@Payload String fname, @Header String lname) { - - The third mapping is almost identical to the previous one (with the exception of method pattern), - since the return value will be mapped to the Message payload by default if nothing else is specified. - + For simple mapping rules you can rely on the publisher defaults. For example: -<publisher id="anotherInterceptor"/> +<publishing-interceptor id="anotherInterceptor"/> This will map the return value of every method that matches the pointcut expression to a payload and will be sent to a default-channel. If the defaultChannelis not specified (as above) the messages will be sent to the global nullChannel.