17
17
18
18
import com .ibm .eventstreams .connect .mqsource .MQSourceConnector ;
19
19
20
+ import java .util .Arrays ;
21
+ import java .util .Enumeration ;
20
22
import java .util .Map ;
21
23
22
24
import javax .jms .JMSContext ;
26
28
import org .apache .kafka .connect .data .Schema ;
27
29
import org .apache .kafka .connect .data .SchemaAndValue ;
28
30
import org .apache .kafka .connect .errors .ConnectException ;
31
+ import org .apache .kafka .connect .header .ConnectHeaders ;
32
+ import org .apache .kafka .connect .header .Header ;
33
+ import org .apache .kafka .connect .header .Headers ;
29
34
import org .apache .kafka .connect .source .SourceRecord ;
30
35
31
36
import org .slf4j .Logger ;
@@ -159,6 +164,36 @@ public SchemaAndValue getKey(JMSContext context, String topic, Message message)
159
164
SchemaAndValue key = this .getKey (context , topic , message );
160
165
SchemaAndValue value = this .getValue (context , topic , messageBodyJms , message );
161
166
162
- return new SourceRecord (null , null , topic , key .schema (), key .value (), value .schema (), value .value ());
167
+ //SourceRecord sourceRecord = new SourceRecord(null, null, topic, key.schema(), key.value(), value.schema(), value.value());
168
+ ConnectHeaders connectHeaders = convertJmsPropertiesToKafkaHeaders (messageBodyJms , message );
169
+ SourceRecord sourceRecord = new SourceRecord (null , null , topic , (Integer )null , key .schema (), key .value (), value .schema (), value .value (), message .getJMSTimestamp (), connectHeaders );
170
+
171
+ return sourceRecord ;
172
+ }
173
+
174
+ public ConnectHeaders convertJmsPropertiesToKafkaHeaders (boolean messageBodyJms , Message message ){
175
+
176
+ ConnectHeaders connectHeaders = new ConnectHeaders ();
177
+
178
+ if (messageBodyJms ==true ) {
179
+
180
+ try {
181
+ Enumeration jmsPropertyNames = message .getPropertyNames ();
182
+ while (jmsPropertyNames .hasMoreElements ()) {
183
+ Object jmsPropertyKey = jmsPropertyNames .nextElement ();
184
+ String jmsPropertyValue = message .getStringProperty (jmsPropertyKey .toString ());
185
+ connectHeaders .addString (jmsPropertyKey .toString (), jmsPropertyValue );
186
+
187
+ }
188
+ }
189
+ catch (JMSException e ){
190
+ log .error ("MQ/JMS message header could not be read" , e );
191
+ }
192
+
193
+
194
+ }
195
+
196
+ return connectHeaders ;
197
+
163
198
}
164
199
}
0 commit comments