1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
package org.apache.camel.component.jms; |
19 |
|
|
20 |
|
import org.apache.camel.impl.PollingConsumerSupport; |
21 |
|
import org.springframework.jms.core.JmsOperations; |
22 |
|
import org.springframework.jms.core.JmsTemplate; |
23 |
|
import org.springframework.jms.core.JmsTemplate102; |
24 |
|
|
25 |
|
import javax.jms.Message; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
0 |
public class JmsPollingConsumer extends PollingConsumerSupport<JmsExchange> { |
31 |
|
private JmsOperations template; |
32 |
|
|
33 |
|
public JmsPollingConsumer(JmsEndpoint endpoint, JmsOperations template) { |
34 |
0 |
super(endpoint); |
35 |
0 |
this.template = template; |
36 |
0 |
} |
37 |
|
|
38 |
|
@Override |
39 |
|
public JmsEndpoint getEndpoint() { |
40 |
0 |
return (JmsEndpoint) super.getEndpoint(); |
41 |
|
} |
42 |
|
|
43 |
|
public JmsExchange receiveNoWait() { |
44 |
0 |
return receive(0); |
45 |
|
} |
46 |
|
|
47 |
|
public JmsExchange receive() { |
48 |
0 |
return receive(-1); |
49 |
|
} |
50 |
|
|
51 |
|
public JmsExchange receive(long timeout) { |
52 |
0 |
setReceiveTimeout(timeout); |
53 |
0 |
Message message = template.receive(); |
54 |
0 |
if (message != null) { |
55 |
0 |
return getEndpoint().createExchange(message); |
56 |
|
} |
57 |
0 |
return null; |
58 |
|
} |
59 |
|
|
60 |
|
protected void doStart() throws Exception { |
61 |
0 |
} |
62 |
|
|
63 |
|
protected void doStop() throws Exception { |
64 |
0 |
} |
65 |
|
|
66 |
|
protected void setReceiveTimeout(long timeout) { |
67 |
0 |
if (template instanceof JmsTemplate) { |
68 |
0 |
JmsTemplate jmsTemplate = (JmsTemplate) template; |
69 |
0 |
jmsTemplate.setReceiveTimeout(timeout); |
70 |
0 |
} |
71 |
0 |
else if (template instanceof JmsTemplate102) { |
72 |
0 |
JmsTemplate102 jmsTemplate102 = (JmsTemplate102) template; |
73 |
0 |
jmsTemplate102.setReceiveTimeout(timeout); |
74 |
0 |
} |
75 |
|
else { |
76 |
0 |
throw new IllegalArgumentException("Cannot set the receiveTimeout property on unknown JmsOperations type: " + template); |
77 |
|
} |
78 |
0 |
} |
79 |
|
} |