Skip to content

Commit 3f2ed1a

Browse files
Merge pull request grails-plugins#4 from charliek/master
Update spring build so queues and exchanges build, and update to new version number
2 parents 4a07110 + 1e9dae7 commit 3f2ed1a

File tree

2 files changed

+86
-20
lines changed

2 files changed

+86
-20
lines changed

RabbitmqGrailsPlugin.groovy

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.springframework.amqp.rabbit.core.RabbitAdmin
88
import org.springframework.amqp.rabbit.core.RabbitTemplate
99
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
1010
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter
11-
11+
import static org.springframework.amqp.core.Binding.DestinationType.QUEUE
1212

1313
class RabbitmqGrailsPlugin {
1414
// the plugin version
15-
def version = "0.3.1"
15+
def version = "0.3.3"
1616
// the version or versions of Grails the plugin is designed for
1717
def grailsVersion = "1.2 > *"
1818
// the other plugins this plugin depends on
@@ -104,7 +104,7 @@ The Rabbit MQ plugin provides integration with the Rabbit MQ Messaging System.
104104
channelTransacted = transactional
105105
connectionFactory = rabbitMQConnectionFactory
106106
concurrentConsumers = connectionFactoryConsumers
107-
queueName = rabbitQueue
107+
queueNames = rabbitQueue
108108
}
109109
}
110110
else {
@@ -147,26 +147,25 @@ The Rabbit MQ plugin provides integration with the Rabbit MQ Messaging System.
147147
if (log.debugEnabled) {
148148
log.debug "Registering exchange '${exchange.name}'"
149149
}
150-
151-
"grails.rabbit.exchange.${exchange.name}"(exchange.type, exchange.name) {
152-
durable = Boolean.valueOf(exchange.durable)
153-
autoDelete = Boolean.valueOf(exchange.autoDelete)
154-
arguments = exchange.arguments
155-
}
150+
151+
"grails.rabbit.exchange.${exchange.name}"(exchange.type, exchange.name,
152+
Boolean.valueOf(exchange.durable),
153+
Boolean.valueOf(exchange.autoDelete),
154+
exchange.arguments)
156155
}
157156

158157
// Next, the queues.
159158
queueBuilder.queues?.each { queue ->
160159
if (log.debugEnabled) {
161160
log.debug "Registering queue '${queue.name}'"
162161
}
163-
164-
"grails.rabbit.queue.${queue.name}"(Queue, queue.name) {
165-
durable = queue.durable
166-
autoDelete = queue.autoDelete
167-
exclusive = queue.exclusive
168-
arguments = queue.arguments
169-
}
162+
163+
"grails.rabbit.queue.${queue.name}"(Queue, queue.name,
164+
Boolean.valueOf(queue.durable),
165+
Boolean.valueOf(queue.exclusive),
166+
Boolean.valueOf(queue.autoDelete),
167+
queue.arguments,
168+
)
170169
}
171170

172171
// Finally, the bindings between exchanges and queues.
@@ -183,10 +182,8 @@ The Rabbit MQ plugin provides integration with the Rabbit MQ Messaging System.
183182
// is the only valid option atm) are passed through as is.
184183
args << (binding.rule instanceof CharSequence ? binding.rule.toString() : binding.rule)
185184
}
186-
187-
"grails.rabbit.binding.${binding.exchange}.${binding.queue}"(Binding, *args) {
188-
arguments = binding.arguments
189-
}
185+
186+
"grails.rabbit.binding.${binding.exchange}.${binding.queue}"(Binding, binding.queue, QUEUE, binding.exchange, binding.rule, binding.arguments )
190187
}
191188
}
192189
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.grails.rabbitmq
2+
3+
import grails.spring.BeanBuilder
4+
import org.springframework.amqp.core.TopicExchange
5+
import org.springframework.amqp.core.Queue
6+
import org.springframework.amqp.core.Binding
7+
import org.springframework.amqp.core.Binding.DestinationType
8+
9+
/**
10+
* Test cases for main plugin file setup.
11+
*/
12+
class RabbitGrailsPluginTests extends GroovyTestCase {
13+
14+
void testQueueAndExchangeSetup(){
15+
// load the base plugin file
16+
String[] roots = ['./']
17+
ClassLoader loader = this.getClass().getClassLoader()
18+
def engine = new GroovyScriptEngine(roots, loader)
19+
def pluginClass = engine.loadScriptByName('RabbitmqGrailsPlugin.groovy')
20+
def base = pluginClass.newInstance()
21+
22+
// mock up test configuration
23+
base.metaClass.application = [:]
24+
base.application.config = new ConfigSlurper().parse("""
25+
rabbitmq {
26+
connectionfactory {
27+
username = 'guest'
28+
password = 'guest'
29+
hostname = 'localhost'
30+
}
31+
32+
queues = {
33+
exchange name: 'it_topic', durable: true, type: topic, autoDelete: false, {
34+
it_q1 autoDelete: false, durable: true, binding: '#', arguments: ['x-ha-policy' : 'all']
35+
}
36+
}
37+
}
38+
""")
39+
40+
// run a spring builder to create context
41+
def bb = new BeanBuilder()
42+
bb.beans base.doWithSpring
43+
def ctx = bb.createApplicationContext()
44+
45+
// test topic
46+
def itTopic = ctx.getBean("grails.rabbit.exchange.it_topic")
47+
assertEquals(itTopic.getClass(), TopicExchange.class)
48+
assertTrue(itTopic.durable)
49+
assertFalse(itTopic.autoDelete)
50+
assertEquals(itTopic.name, 'it_topic')
51+
52+
// test queue
53+
def itQ1 = ctx.getBean("grails.rabbit.queue.it_q1")
54+
assertEquals(itQ1.getClass(), Queue.class)
55+
assertEquals(itQ1.name, "it_q1")
56+
assertEquals(itQ1.durable, true)
57+
assertEquals(itQ1.autoDelete, false)
58+
assertEquals(itQ1.arguments['x-ha-policy'], 'all')
59+
60+
// test binding
61+
def ibBind = ctx.getBean("grails.rabbit.binding.it_topic.it_q1")
62+
assertEquals(ibBind.getClass(), Binding.class)
63+
assertEquals(ibBind.destination, 'it_q1')
64+
assertEquals(ibBind.exchange, 'it_topic')
65+
assertEquals(ibBind.routingKey, '#')
66+
assertEquals(ibBind.destinationType, DestinationType.QUEUE)
67+
}
68+
69+
}

0 commit comments

Comments
 (0)