forked from oleksiivorobiov/oracle_oci_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aqdemo01.sql
374 lines (284 loc) · 8.53 KB
/
aqdemo01.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
Rem
Rem $Header: template.sql 06-feb-96.13:23:14 kosinski Exp $
Rem
Rem aqdemo01.sql
Rem
Rem Copyright (c) Oracle Corporation 2000. All Rights Reserved.
Rem
Rem NAME
Rem aqdemo01.sql - <one-line expansion of the name>
Rem
Rem DESCRIPTION
rem This file creates queue tables, queues, subscribers needed for
rem the demo. Propagation is scheduled between input_queue and other
rem queues in the same database
Rem
Rem NOTES
Rem <other useful comments, qualifications, etc.>
Rem
Rem MODIFIED (MM/DD/YY)
Rem rbhyrava 07/10/00 - Created - bug :1319922
rem mjaeger 07/14/99 - bug 808870: OCCS: convert tabs, no long lines
rem kmeiyyap 09/15/98 - Created
Rem
rem Create Queue table, Queues, Subscribers
connect aquser/aquser
set serveroutput on
set echo on
rem ==============================
rem Error Handling Routine
rem ==============================
CREATE or REPLACE PROCEDURE catch_error ( error_code in number,
error_string in varchar2)
AS
BEGIN
dbms_output.put_line('Oracle Server Error = '|| to_char (error_code));
dbms_output.put_line('Oracle Server Message = '|| error_string);
END;
/
rem ==========================================
rem Stop Queue input_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Stopping Queue input_queue...');
dbms_aqadm.stop_queue
(
queue_name => 'input_queue',
wait => TRUE
);
dbms_output.put_line ('Stopped Queue input_queue.');
exception
when others then
catch_error(SQLCODE, 'Stop Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Stop Queue prop_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Stopping Queue prop_queue...');
dbms_aqadm.stop_queue
(
queue_name => 'prop_queue',
wait => TRUE
);
dbms_output.put_line ('Stopped Queue prop_queue.');
exception
when others then
catch_error(SQLCODE, 'Stop Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Drop Queue input_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Dropping Queue input_queue...');
dbms_aqadm.drop_queue
(
queue_name => 'input_queue'
);
dbms_output.put_line ('Dropped Queue input_queue.');
exception
when others then
catch_error(SQLCODE, 'Drop Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Drop Queue prop_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Dropping Queue prop_queue...');
dbms_aqadm.drop_queue
(
queue_name => 'prop_queue'
);
dbms_output.put_line ('Dropped Queue prop_queue.');
exception
when others then
catch_error(SQLCODE, 'Drop Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Drop Input Queue Table
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Dropping Queue Table input_queue_table...');
dbms_aqadm.drop_queue_table
(
queue_table => 'input_queue_table',
force => TRUE
);
dbms_output.put_line ('Dropped Queue Table input_queue_table.');
exception
when others then
catch_error(SQLCODE, 'Drop Queue Table ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Drop Prop Queue Table
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Dropping Queue Table prop_queue_table...');
dbms_aqadm.drop_queue_table
(
queue_table => 'prop_queue_table',
force => TRUE
);
dbms_output.put_line ('Dropped Queue Table prop_queue_table.');
exception
when others then
catch_error(SQLCODE, 'Drop Queue Table ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Create a queue table input_queue_table
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Creating Queue Table input_queue_table...');
dbms_aqadm.CREATE_queue_table(
queue_table => 'input_queue_table',
multiple_consumers => TRUE,
queue_payload_type => 'message',
compatible => '8.1.3',
comment => 'Creating input queue table');
dbms_output.put_line ('Created Queue Table input_queue_table.');
exception
when others then
catch_error(SQLCODE, 'Create Queue Table ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Create a queue table prop_queue_table
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Creating Queue Table prop_queue_table...');
dbms_aqadm.CREATE_queue_table(
queue_table => 'prop_queue_table',
multiple_consumers => TRUE,
queue_payload_type => 'message',
compatible => '8.1.3',
comment => 'Creating prop queue table');
dbms_output.put_line ('Created Queue Table prop_queue_table.');
exception
when others then
catch_error(SQLCODE, 'Create Queue Table ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Create a queue input_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Creating Queue input_queue...');
dbms_aqadm.CREATE_queue(
queue_name => 'input_queue',
queue_table => 'input_queue_table',
comment => 'Demo Queue');
dbms_output.put_line ('Created Queue input_queue.');
exception
when others then
catch_error(SQLCODE, 'Create Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ==========================================
rem Create a queue prop_queue
rem ==========================================
DECLARE
BEGIN
dbms_output.put_line ('Creating Queue prop_queue...');
dbms_aqadm.CREATE_queue(
queue_name => 'prop_queue',
queue_table => 'prop_queue_table',
comment => 'Propagation Queue');
dbms_output.put_line ('Created Queue prop_queue.');
exception
when others then
catch_error(SQLCODE, 'Create Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ====================================
rem Start input queue input_queue
rem ====================================
DECLARE
BEGIN
dbms_output.put_line('starting queue input_queue...');
dbms_aqadm.start_queue(
queue_name => 'input_queue');
dbms_output.put_line ('Started Queue input_queue.');
exception
when others then
catch_error(SQLCODE, 'Start Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ====================================
rem Start input queue prop_queue
rem ====================================
DECLARE
BEGIN
dbms_output.put_line('starting Prop queue prop_queue...');
dbms_aqadm.start_queue(
queue_name => 'prop_queue');
dbms_output.put_line ('Started Queue prop_queue.');
exception
when others then
catch_error(SQLCODE, 'Start Queue ' || substr(SQLERRM, 1, 256));
END;
/
rem ========================================
rem Create queue subscribers
rem ========================================
DECLARE
subscriber sys.aq$_agent;
BEGIN
subscriber := sys.aq$_agent('prog1', NULL, NULL);
dbms_aqadm.add_subscriber(
queue_name => 'input_queue',
subscriber => subscriber);
dbms_output.put_line ('Added subscriber prog1 to input_queue.');
END;
/
DECLARE
subscriber1 sys.aq$_agent;
BEGIN
subscriber1 := sys.aq$_agent('prog2', NULL, NULL);
dbms_aqadm.add_subscriber(
queue_name => 'input_queue',
subscriber => subscriber1,
rule => 'priority > 2');
dbms_output.put_line ('Added subscriber prog2 to input_queue.');
END;
/
DECLARE
subscriber sys.aq$_agent;
BEGIN
subscriber := sys.aq$_agent('prog3', 'prop_queue', NULL);
dbms_aqadm.add_subscriber(
queue_name => 'input_queue',
subscriber => subscriber,
rule => 'priority = 2');
dbms_output.put_line ('Added subscriber prog3@prop_queue to input_queue.');
END;
/
rem ========================================
rem Schedule propagation
rem ========================================
DECLARE
BEGIN
dbms_aqadm.schedule_propagation(
queue_name => 'input_queue',
latency => '10');
dbms_output.put_line (
'Scheduled propagation from input_queue to other queues.');
END;
/
rem ========================================
rem Setup complete
rem ========================================