From 7b1c8aa805f17d353c21cb31b50cb31e1eca3905 Mon Sep 17 00:00:00 2001 From: danhaywood Date: Thu, 3 Oct 2019 12:56:36 +0100 Subject: [PATCH] #110 - reimplemented after the changes made in #115 --- .../spi/InteractionExecutionRepositoryMq.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/spi/publishmq/impl/mq/src/main/java/org/isisaddons/module/publishmq/dom/mq/spi/InteractionExecutionRepositoryMq.java b/modules/spi/publishmq/impl/mq/src/main/java/org/isisaddons/module/publishmq/dom/mq/spi/InteractionExecutionRepositoryMq.java index 706520189..3b33d8f69 100644 --- a/modules/spi/publishmq/impl/mq/src/main/java/org/isisaddons/module/publishmq/dom/mq/spi/InteractionExecutionRepositoryMq.java +++ b/modules/spi/publishmq/impl/mq/src/main/java/org/isisaddons/module/publishmq/dom/mq/spi/InteractionExecutionRepositoryMq.java @@ -49,6 +49,10 @@ public class InteractionExecutionRepositoryMq implements InteractionExecutionRep public static final String KEY_MEMBER_INTERACTIONS_QUEUE = ROOT + "memberInteractionsQueue"; public static final String KEY_MEMBER_INTERACTIONS_QUEUE_DEFAULT = "memberInteractionsQueue"; + + public static final String KEY_PROPAGATE_EXCEPTION = ROOT + "propagateException"; + public static final String KEY_PROPAGATE_EXCEPTION_DEFAULT = "false"; + //endregion @@ -65,6 +69,8 @@ public class InteractionExecutionRepositoryMq implements InteractionExecutionRep private boolean enabled; + private boolean propagateException; + //endregion //region > init, shutdown @@ -85,6 +91,8 @@ public void init(Map properties) { memberInteractionsQueueName = properties.getOrDefault(KEY_MEMBER_INTERACTIONS_QUEUE, KEY_MEMBER_INTERACTIONS_QUEUE_DEFAULT); + propagateException = properties.getOrDefault(KEY_PROPAGATE_EXCEPTION, KEY_PROPAGATE_EXCEPTION_DEFAULT).equalsIgnoreCase("true"); + connect(); } @@ -192,9 +200,17 @@ private void sendUsingJms(final InteractionDto interactionDto) { session.commit(); - } catch (JMSException e) { + } catch (JMSException ex) { rollback(session); - throw new ApplicationException("Failed to publish message", e); + if(propagateException) { + throw new ApplicationException(String.format( + "Failed to publish message, and aborting (as per '%s' property)", KEY_PROPAGATE_EXCEPTION), + ex); + } else { + LOG.error(String.format( + "Failed to publish message, but continuing (as per '%s' property)", KEY_PROPAGATE_EXCEPTION), + ex); + } } finally { if(session != null) { closeSafely(session);