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