1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.camel.component.jms; |
18 |
|
|
19 |
|
import javax.jms.Message; |
20 |
|
|
21 |
|
import org.apache.camel.PollingConsumer; |
22 |
|
import org.apache.camel.Processor; |
23 |
|
import org.apache.camel.impl.DefaultEndpoint; |
24 |
|
|
25 |
|
import org.springframework.jms.core.JmsOperations; |
26 |
|
import org.springframework.jms.core.JmsTemplate; |
27 |
|
import org.springframework.jms.listener.AbstractMessageListenerContainer; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
142 |
public class JmsEndpoint extends DefaultEndpoint<JmsExchange> { |
35 |
|
private JmsBinding binding; |
36 |
|
private String destination; |
37 |
|
private final boolean pubSubDomain; |
38 |
|
private String selector; |
39 |
|
private JmsConfiguration configuration; |
40 |
|
|
41 |
|
public JmsEndpoint(String uri, JmsComponent component, String destination, boolean pubSubDomain, JmsConfiguration configuration) { |
42 |
133 |
super(uri, component); |
43 |
133 |
this.configuration = configuration; |
44 |
133 |
this.destination = destination; |
45 |
133 |
this.pubSubDomain = pubSubDomain; |
46 |
133 |
} |
47 |
|
|
48 |
|
public JmsProducer createProducer() throws Exception { |
49 |
52 |
JmsOperations template = createJmsOperations(); |
50 |
52 |
return createProducer(template); |
51 |
|
} |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
public JmsProducer createProducer(JmsOperations template) throws Exception { |
57 |
52 |
if (template instanceof JmsTemplate) { |
58 |
52 |
JmsTemplate jmsTemplate = (JmsTemplate)template; |
59 |
52 |
jmsTemplate.setPubSubDomain(pubSubDomain); |
60 |
52 |
jmsTemplate.setDefaultDestinationName(destination); |
61 |
|
} |
62 |
52 |
return new JmsProducer(this, template); |
63 |
|
} |
64 |
|
|
65 |
|
public JmsConsumer createConsumer(Processor processor) throws Exception { |
66 |
81 |
AbstractMessageListenerContainer listenerContainer = configuration.createMessageListenerContainer(); |
67 |
81 |
return createConsumer(processor, listenerContainer); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
public JmsConsumer createConsumer(Processor processor, AbstractMessageListenerContainer listenerContainer) throws Exception { |
79 |
81 |
listenerContainer.setDestinationName(destination); |
80 |
81 |
listenerContainer.setPubSubDomain(pubSubDomain); |
81 |
81 |
if (selector != null) { |
82 |
0 |
listenerContainer.setMessageSelector(selector); |
83 |
|
} |
84 |
81 |
return new JmsConsumer(this, processor, listenerContainer); |
85 |
|
} |
86 |
|
|
87 |
|
@Override |
88 |
|
public PollingConsumer<JmsExchange> createPollingConsumer() throws Exception { |
89 |
0 |
JmsOperations template = createJmsOperations(); |
90 |
0 |
return new JmsPollingConsumer(this, template); |
91 |
|
} |
92 |
|
|
93 |
|
public JmsExchange createExchange() { |
94 |
11 |
return new JmsExchange(getContext(), getBinding()); |
95 |
|
} |
96 |
|
|
97 |
|
public JmsExchange createExchange(Message message) { |
98 |
0 |
return new JmsExchange(getContext(), getBinding(), message); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
public JmsBinding getBinding() { |
104 |
119 |
if (binding == null) { |
105 |
103 |
binding = new JmsBinding(); |
106 |
|
} |
107 |
119 |
return binding; |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
public void setBinding(JmsBinding binding) { |
117 |
0 |
this.binding = binding; |
118 |
0 |
} |
119 |
|
|
120 |
|
public String getDestination() { |
121 |
27 |
return destination; |
122 |
|
} |
123 |
|
|
124 |
|
public JmsConfiguration getConfiguration() { |
125 |
202 |
return configuration; |
126 |
|
} |
127 |
|
|
128 |
|
public String getSelector() { |
129 |
0 |
return selector; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
public void setSelector(String selector) { |
136 |
0 |
this.selector = selector; |
137 |
0 |
} |
138 |
|
|
139 |
|
public boolean isSingleton() { |
140 |
133 |
return false; |
141 |
|
} |
142 |
|
|
143 |
|
protected JmsOperations createJmsOperations() { |
144 |
52 |
return configuration.createJmsOperations(pubSubDomain, destination); |
145 |
|
} |
146 |
|
|
147 |
|
} |