Skip to content

Commit 99d456b

Browse files
Modify exception handling for unparseable messages
1 parent 35ace10 commit 99d456b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/main/java/com/ibm/eventstreams/connect/mqsource/JMSReader.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package com.ibm.eventstreams.connect.mqsource;
1717

18+
import com.ibm.eventstreams.connect.mqsource.builders.RecordBuilder;
19+
1820
import com.ibm.mq.MQException;
1921
import com.ibm.mq.constants.MQConstants;
2022
import com.ibm.mq.jms.*;
21-
import com.ibm.eventstreams.connect.mqsource.builders.RecordBuilder;
2223
import com.ibm.msg.client.wmq.WMQConstants;
2324

2425
import java.util.Map;
@@ -215,10 +216,14 @@ public SourceRecord receive(boolean wait) {
215216
inperil = false;
216217
}
217218
}
218-
catch (JMSException | JMSRuntimeException | ConnectException exc) {
219+
catch (JMSException | JMSRuntimeException exc) {
219220
log.error("JMS exception {}", exc);
220221
handleException(exc);
221222
}
223+
catch (ConnectException exc) {
224+
log.error("Connect exception {}", exc);
225+
throw exc;
226+
}
222227

223228
log.trace("[{}] Exit {}.receive, retval={}", Thread.currentThread().getId(), this.getClass().getName(), sr);
224229
return sr;
@@ -266,7 +271,9 @@ public void close() {
266271
try {
267272
JMSContext ctxt = jmsCtxt;
268273
closeNow.set(true);
269-
ctxt.close();
274+
if (ctxt != null) {
275+
ctxt.close();
276+
}
270277
}
271278
catch (JMSRuntimeException jmse) {
272279
;
@@ -375,6 +382,11 @@ private ConnectException handleException(Throwable exc) {
375382
reason = mqe.getReason();
376383
break;
377384
}
385+
else if (t instanceof JMSException) {
386+
JMSException jmse = (JMSException)t;
387+
log.error("JMS exception: error code {}", jmse.getErrorCode());
388+
}
389+
378390
t = t.getCause();
379391
}
380392

@@ -394,7 +406,7 @@ private ConnectException handleException(Throwable exc) {
394406
isRetriable = true;
395407
break;
396408

397-
// These reason codes indicate that the connect is still OK, but just retrying later
409+
// These reason codes indicate that the connection is still OK, but just retrying later
398410
// will probably recover - possibly with administrative action on the queue manager
399411
case MQConstants.MQRC_GET_INHIBITED:
400412
isRetriable = true;
@@ -403,6 +415,13 @@ private ConnectException handleException(Throwable exc) {
403415
}
404416

405417
if (mustClose) {
418+
// Delay so that repeated reconnect loops don't run too fast
419+
try {
420+
Thread.sleep(RECONNECT_DELAY_MILLIS_MAX);
421+
}
422+
catch (InterruptedException ie) {
423+
;
424+
}
406425
closeInternal();
407426
}
408427

0 commit comments

Comments
 (0)