|
1 | 1 |
|
2 | 2 | This plugin makes it easy to both send and receive JMS messages inside a Grails application. |
3 | | -== Include in project |
4 | 3 |
|
5 | | -The plugin is available on Maven Central and should be a dependency like this: |
6 | 4 |
|
7 | | -[source,groovy,subs="attributes"] |
8 | | ----- |
9 | | -dependencies { |
10 | | - compile 'io.github.gpc:jms:{version}' |
11 | | -} |
12 | | ----- |
13 | | - |
14 | | -In newer Gradle versions, replace `compile` with `implementation` |
15 | | - |
16 | | -== Examples |
17 | | - |
18 | | -The following are some simple examples to give you a feel for the plugin. |
19 | | - |
20 | | - |
21 | | -=== Service Queue Listeners |
22 | | - |
23 | | -[source,groovy] |
24 | | ----- |
25 | | -class ListeningService { |
26 | | -
|
27 | | - static exposes = ['jms'] |
28 | | -
|
29 | | - def onMessage(message) { |
30 | | - assert message == 1 |
31 | | - } |
32 | | -} |
33 | | ----- |
34 | | - |
35 | | -[source,groovy] |
36 | | ----- |
37 | | -class SomeController { |
38 | | -
|
39 | | - def jmsService |
40 | | -
|
41 | | - def someAction = { |
42 | | - jmsService.send(service: 'listening', 1) |
43 | | - } |
44 | | -} |
45 | | ----- |
46 | | - |
47 | | -=== Service Method Queue Listeners |
48 | | - |
49 | | -[source,groovy] |
50 | | ----- |
51 | | -import grails.plugin.jms.Queue |
52 | | -
|
53 | | -class ListeningService { |
54 | | -
|
55 | | - static exposes = ['jms'] |
56 | | -
|
57 | | - @Queue |
58 | | - def receive(message) { |
59 | | - assert message == 1 |
60 | | - } |
61 | | -} |
62 | | ----- |
63 | | - |
64 | | -[source,groovy] |
65 | | ----- |
66 | | -class SomeController { |
67 | | -
|
68 | | - def jmsService |
69 | | -
|
70 | | - def someAction = { |
71 | | - jmsService.send(service: 'listening', method: 'receive', 1) |
72 | | - } |
73 | | -} |
74 | | ----- |
75 | | - |
76 | | -=== Topic Listeners |
77 | | - |
78 | | -[source,groovy] |
79 | | ----- |
80 | | -import grails.plugin.jms.Subscriber |
81 | | -
|
82 | | -class ListeningService { |
83 | | -
|
84 | | - static exposes = ['jms'] |
85 | | -
|
86 | | - @Subscriber |
87 | | - def newMessages(message) { |
88 | | - assert message == 1 |
89 | | - } |
90 | | -} |
91 | | ----- |
92 | | - |
93 | | -[source,groovy] |
94 | | ----- |
95 | | -class SomeController { |
96 | | -
|
97 | | - def jmsService |
98 | | -
|
99 | | - def someAction = { |
100 | | - jmsService.send(topic: 'newMessages', 1) |
101 | | - } |
102 | | -} |
103 | | ----- |
104 | | - |
105 | | -=== Post Processing Messages |
106 | | - |
107 | | -[source,groovy] |
108 | | ----- |
109 | | -import javax.jms.Message |
110 | | -
|
111 | | -class SomeController { |
112 | | -
|
113 | | - def jmsService |
114 | | -
|
115 | | - def someAction = { |
116 | | - jmsService.send(service: 'initial', 1) { Message msg -> |
117 | | - msg.JMSReplyTo = createDestination(service: 'reply') |
118 | | - msg |
119 | | - } |
120 | | - } |
121 | | -} |
122 | | ----- |
0 commit comments