Permalink
Browse files

Started on AMQP support

  • Loading branch information...
dturanski committed May 27, 2012
1 parent cca0e62 commit d658099275fc7905fa56fd287bcbafac98ae8616
Showing with 420 additions and 20 deletions.
  1. +8 −0 build.gradle
  2. +1 −0 settings.gradle
  3. +25 −0 ...-groovy-amqp/src/main/groovy/org/springframework/integration/dsl/groovy/amqp/RabbitContext.groovy
  4. +43 −0 ...vy/org/springframework/integration/dsl/groovy/amqp/builder/IntegrationBuilderModuleSupport.groovy
  5. +34 −0 ...src/main/groovy/org/springframework/integration/dsl/groovy/amqp/builder/RabbitAdminFactory.groovy
  6. +33 −0 ...ovy/org/springframework/integration/dsl/groovy/amqp/builder/RabbitConnectionFactoryFactory.groovy
  7. +31 −0 ...c/main/groovy/org/springframework/integration/dsl/groovy/amqp/builder/RabbitContextFactory.groovy
  8. +48 −0 .../main/groovy/org/springframework/integration/dsl/groovy/amqp/builder/RabbitExchangeFactory.groovy
  9. +33 −0 ...src/main/groovy/org/springframework/integration/dsl/groovy/amqp/builder/RabbitQueueFactory.groovy
  10. +52 −0 ...mqp/src/test/groovy/org/springframework/integration/dsl/groovy/amqp/builder/AmqpUsageTests.groovy
  11. +29 −0 spring-integration-dsl-groovy-amqp/src/test/resources/log4j.xml
  12. +22 −0 ...groovy-core/src/main/groovy/org/springframework/integration/dsl/groovy/SpringModuleContext.groovy
  13. +1 −0 ...gration-dsl-groovy-core/src/main/groovy/org/springframework/integration/dsl/groovy/XMLBean.groovy
  14. +3 −2 ...core/src/main/groovy/org/springframework/integration/dsl/groovy/builder/IntegrationBuilder.groovy
  15. +8 −5 ...main/groovy/org/springframework/integration/dsl/groovy/builder/IntegrationComponentFactory.groovy
  16. +3 −5 ...c/main/groovy/org/springframework/integration/dsl/groovy/builder/IntegrationContextFactory.groovy
  17. +1 −1 ...core/src/main/groovy/org/springframework/integration/dsl/groovy/builder/MessageFlowFactory.groovy
  18. +1 −1 ...oovy-core/src/main/groovy/org/springframework/integration/dsl/groovy/builder/PollerFactory.groovy
  19. +1 −1 ...vy-core/src/main/groovy/org/springframework/integration/dsl/groovy/builder/RouterFactories.groovy
  20. +1 −1 ...src/main/groovy/org/springframework/integration/dsl/groovy/builder/SimpleEndpointFactories.groovy
  21. +34 −0 ...c/main/groovy/org/springframework/integration/dsl/groovy/builder/SpringXmlComponentFactory.groovy
  22. +2 −2 ...ovy-core/src/main/groovy/org/springframework/integration/dsl/groovy/builder/XMLBeanFactory.groovy
  23. +1 −1 ...ore/src/main/groovy/org/springframework/integration/dsl/groovy/builder/XMLNamespaceFactory.groovy
  24. +3 −0 ...c/main/groovy/org/springframework/integration/dsl/groovy/builder/dom/IntegrationDomSupport.groovy
  25. +1 −1 ...ain/groovy/org/springframework/integration/dsl/groovy/builder/dom/SimpleEndpointDomBuilder.groovy
  26. +1 −0 ...re/src/main/groovy/org/springframework/integration/dsl/groovy/builder/dom/SpringXMLBuilder.groovy
View
@@ -75,6 +75,14 @@ project('spring-integration-dsl-groovy-jms') {
}
}
+project('spring-integration-dsl-groovy-amqp') {
+ description = 'Spring Integration Groovy DSL AMQP'
+ dependencies {
+ compile project(":spring-integration-dsl-groovy-core")
+ compile "org.springframework.integration:spring-integration-amqp:$springIntegrationVersion"
+ }
+}
+
project('spring-integration-dsl-groovy-http') {
description = 'Spring Integration Groovy DSL Http'
dependencies {
View
@@ -1,5 +1,6 @@
rootProject.name = 'spring-integration-dsl-groovy'
include 'spring-integration-dsl-groovy-core'
+include 'spring-integration-dsl-groovy-amqp'
include 'spring-integration-dsl-groovy-http'
include 'spring-integration-dsl-groovy-jms'
include 'spring-integration-dsl-groovy-samples'
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp
+import org.springframework.integration.dsl.groovy.SpringModuleContext
+
+/**
+ * @author David Turanski
+ *
+ */
+public class RabbitContext extends SpringModuleContext {
+
+ @Override
+ protected String getNamespacePrefix() {
+ 'rabbit'
+ }}
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder;
+
+import org.springframework.integration.dsl.groovy.builder.AbstractIntegrationBuilderModuleSupport
+import org.springframework.integration.dsl.groovy.builder.IntegrationBuilder
+import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupport
+
+/**
+ * @author David Turanski
+ *
+ */
+class IntegrationBuilderModuleSupport extends AbstractIntegrationBuilderModuleSupport {
+
+ @Override
+ void registerBuilderFactories(IntegrationBuilder builder) {
+ builder.registerFactory 'rabbitDirectExchange', new RabbitExchangeFactory()
+ builder.registerFactory 'rabbitTopicExchange', new RabbitExchangeFactory()
+ builder.registerFactory 'rabbitFanoutExchange', new RabbitExchangeFactory()
+ builder.registerFactory 'rabbitHeadersExchange', new RabbitExchangeFactory()
+ builder.registerFactory 'rabbitFederatedExchange', new RabbitExchangeFactory()
+ builder.registerFactory 'rabbitConnectionFactory', new RabbitConnectionFactoryFactory()
+ builder.registerFactory 'rabbitQueue', new RabbitQueueFactory()
+ builder.registerFactory 'rabbitAdmin', new RabbitAdminFactory()
+ builder.registerFactory 'doWithRabbit', new RabbitContextFactory()
+ }
+
+ @Override
+ void registerDomBuilders(IntegrationDomSupport integrationDomSupport) {
+ integrationDomSupport.namespaceSupport.addIntegrationNamespace('int-amqp')
+ integrationDomSupport.namespaceSupport.addSpringNamespace('rabbit')
+ }
+}
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import groovy.util.FactoryBuilderSupport
+import java.util.Map
+import org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory
+import org.springframework.integration.dsl.groovy.builder.SpringXmlComponentFactory
+
+/**
+ * @author David Turanski
+ *
+ */
+class RabbitAdminFactory extends SpringXmlComponentFactory {
+
+ /* (non-Javadoc)
+ * @see org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory#doNewInstance(groovy.util.FactoryBuilderSupport, java.lang.Object, java.lang.Object, java.util.Map)
+ */
+ @Override
+ protected Object doNewInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
+ String elementName = propertyNameToAttributeName(name).replace('rabbit-','rabbit:')
+ attributes.'connection-factory' ?:'connectionFactory'
+ builder.springXml{"$elementName"(attributes)}
+ }
+}
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import groovy.util.FactoryBuilderSupport
+import java.util.Map
+import org.springframework.integration.dsl.groovy.amqp.RabbitContext
+import org.springframework.integration.dsl.groovy.builder.SpringXmlComponentFactory
+
+/**
+ * @author David Turanski
+ *
+ */
+class RabbitConnectionFactoryFactory extends SpringXmlComponentFactory {
+
+ /* (non-Javadoc)
+ * @see org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory#doNewInstance(groovy.util.FactoryBuilderSupport, java.lang.Object, java.lang.Object, java.util.Map)
+ */
+ @Override
+ protected Object doNewInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
+ def id = attributes.name ?:'connectionFactory'
+ builder.springXml{"rabbit:connection-factory"(id:id)}
+ }
+}
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import groovy.util.FactoryBuilderSupport
+import java.util.Map
+import org.springframework.integration.dsl.groovy.amqp.RabbitContext
+import org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory
+import org.springframework.integration.dsl.groovy.builder.IntegrationContextFactory
+import org.springframework.integration.dsl.groovy.builder.SpringXmlComponentFactory
+
+/**
+ * @author David Turanski
+ *
+ */
+class RabbitContextFactory extends IntegrationContextFactory {
+
+ @Override
+ protected Object doNewInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
+ new RabbitContext()
+ }
+}
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import groovy.util.FactoryBuilderSupport
+import java.util.Map
+import org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory
+import org.springframework.integration.dsl.groovy.builder.SpringXmlComponentFactory
+
+/**
+ * @author David Turanski
+ *
+ */
+class RabbitExchangeFactory extends SpringXmlComponentFactory {
+
+ /* (non-Javadoc)
+ * @see org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory#doNewInstance(groovy.util.FactoryBuilderSupport, java.lang.Object, java.lang.Object, java.util.Map)
+ */
+ @Override
+ protected Object doNewInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
+ String elementName = propertyNameToAttributeName(name).replace('rabbit-','rabbit:')
+
+ def bindings
+ if (attributes.containsKey('bindings')){
+ bindings = attributes.remove('bindings')
+ }
+ builder.springXml{"$elementName"(attributes) {
+ if (bindings){
+ 'rabbit:bindings' {
+ // Expecting a list of Maps
+ bindings.each {Map binding ->
+ 'rabbit:binding'(binding)
+ }
+ }
+ }
+ }
+ }
+ }
+}
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import groovy.util.FactoryBuilderSupport
+import java.util.Map
+import org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory
+import org.springframework.integration.dsl.groovy.builder.SpringXmlComponentFactory
+
+/**
+ * @author David Turanski
+ *
+ */
+class RabbitQueueFactory extends SpringXmlComponentFactory {
+
+ /* (non-Javadoc)
+ * @see org.springframework.integration.dsl.groovy.builder.IntegrationComponentFactory#doNewInstance(groovy.util.FactoryBuilderSupport, java.lang.Object, java.lang.Object, java.util.Map)
+ */
+ @Override
+ protected Object doNewInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
+ String elementName = propertyNameToAttributeName(name).replace('rabbit-','rabbit:')
+ builder.springXml{"$elementName"(attributes)}
+ }
+}
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy.amqp.builder
+import static org.junit.Assert.*
+import org.junit.Test
+import org.springframework.integration.dsl.groovy.builder.IntegrationBuilder
+/**
+ * @author David Turanski
+ *
+ */
+class AmqpUsageTests {
+ def builder = new IntegrationBuilder('amqp')
+
+ @Test
+ void testConnectionFactory() {
+ builder.doWithSpringIntegration {
+ rabbitConnectionFactory()
+ }
+
+ builder.applicationContext.getBean('connectionFactory')
+ }
+
+ @Test
+ void testDirectExchange() {
+ builder.doWithSpringIntegration {
+ rabbitQueue('q1')
+ rabbitQueue('q2')
+ rabbitQueue('q3')
+ rabbitDirectExchange('myExchange',bindings:[[key:'t1',queue:'q1'],[key:'t2',queue:'q2'],[queue:'q3']])
+ }
+
+ builder.applicationContext.getBean('myExchange')
+ }
+
+ @Test
+ void testAdmin() {
+ builder.doWithSpringIntegration {
+ rabbitConnectionFactory('myConnectionFactory')
+ rabbitAdmin(connectionFactory:'myConnectionFactory')
+ }
+ }
+}
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <!-- Appenders -->
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out" />
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%-5p: %c - %m%n" />
+ </layout>
+ </appender>
+
+ <!-- Loggers -->
+
+ <logger name="org.springframework.integration.dsl.groovy">
+ <level value="debug" />
+ </logger>
+
+ <logger name="org.springframework.integration">
+ <level value="debug" />
+ </logger>
+
+ <!-- Root Logger -->
+ <root>
+ <priority value="info" />
+ <appender-ref ref="console" />
+ </root>
+
+</log4j:configuration>
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2002-2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.springframework.integration.dsl.groovy
+
+/**
+ * @author David Turanski
+ *
+ * A marker for Spring module containers
+ */
+abstract class SpringModuleContext extends BaseIntegrationComposition {
+ protected abstract String getNamespacePrefix()
+}
@@ -18,4 +18,5 @@ package org.springframework.integration.dsl.groovy
*/
class XMLBean extends IntegrationComponent {
Closure beanDefinitions
+ String builderName='springXml'
}
Oops, something went wrong.

0 comments on commit d658099

Please sign in to comment.