Announcement Announcement Module
Collapse
No announcement yet.
Combining integration and AMQP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combining integration and AMQP

    I am trying to create a simple spike that is an extension to one of the spring integration samples for transferring files.

    In this original example the config looks like this
    HTML Code:
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
    
    	<file:inbound-channel-adapter id="filesIn"
    	                              directory="file:${java.io.tmpdir}/spring-integration-samples/input"
    	                              >     <!--filename-pattern="[a-z]+.txt"-->
    		<integration:poller id="poller" fixed-delay="5000"/>
    	</file:inbound-channel-adapter>
    
    	<file:file-to-string-transformer input-channel="filesIn" output-channel="strings"/>
    
    	<integration:channel id="strings"/>
    
    	<integration:service-activator input-channel="strings"
    	                               output-channel="filesOut"
                                       ref="handler"/>
    
    	<file:outbound-channel-adapter id="filesOut" directory="file:${java.io.tmpdir}/spring-integration-samples/output"/>
    
    	<bean id="handler" class="org.springframework.integration.samples.filecopy.Handler"/>
    I have changed this to

    HTML Code:
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
        <bean class="org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor"/>
        <integration:annotation-config/>
        <file:inbound-channel-adapter id="filesIn"
    	                              directory="file:${java.io.tmpdir}/spring-integration-samples/input"
    	                              >     <!--filename-pattern="[a-z]+.txt"-->
    		<integration:poller id="poller" fixed-delay="5000"/>
    	</file:inbound-channel-adapter>
    
    	<file:file-to-string-transformer input-channel="filesIn" output-channel="strings"/>
    
    	<integration:channel id="strings"/>
    
        <!-- the handler in this case is responsible for sending messages to a real Q -->
    	<integration:service-activator input-channel="strings" ref="handler"/> <!--output-channel="filesOut"-->
        <bean id="handler" class="com.musa.spike.Handler"/>
    
        <!-- this should be called when the FileMessageHandler gets Fired -->
    	<file:outbound-channel-adapter id="filesOut" directory="file:${java.io.tmpdir}/spring-integration-samples/output"/>
    The handler used to just log and return the same string.

    Now it does this
    Code:
    public void handleString(String input) {System.out.println("Sending file contents to teh default Rabbit MQ Queue");
            ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);
    		AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);
            amqpTemplate.convertAndSend(input);}
    In a separate process I have this target setup as a message listener

    Code:
    public class FileMessageHandler {
    
    	@Publisher(channel="filesOut")
        public String handleMessage(String text) {
    		System.out.println("Received: message from Rabbit MQ");
            return text;
    	}
    
    }
    This gets called as expected but the output-channel-adapter is not being invoked.

    HTML Code:
    <file:outbound-channel-adapter id="filesOut" directory="file:${java.io.tmpdir}/spring-integration-samples/output"/>
    I have added
    HTML Code:
    <bean class="org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor"/>
        <integration:annotation-config/>
    To the integration xml file. Can anyone tell me what I may have missed?

  • #2
    Your handler has a void return type, so there is nothing to forward to the output channel.

    N.B. there is a spring-integration-amqp adapter module in the Spring Integration source (not released with 2.0 because Spring AMQP is not ready yet). You could have used that to send the message through a gateway, which would have been more idiomatic in integration terms.

    Comment


    • #3
      Your handler has a void return type, so there is nothing to forward to the output channel.
      This is deliberate as the message at this point gets passed to RabbitMQ it does not go to an output channel. I have managed to complete the process and have posted the result here

      N.B. there is a spring-integration-amqp adapter module in the Spring Integration source (not released with 2.0 because Spring AMQP is not ready yet). You could have used that to send the message through a gateway, which would have been more idiomatic in integration terms.
      I did look at this but I was not sure it was fully functional in the sandbox. There was no POM so I could not resolve dependencies and build the sandbox source. I agree that your suggestion would be the desired approach and would be far more consistent with the idioms of the rest of the framework.

      Thanks

      Simon

      Comment

      Working...
      X