Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit e9e4775

Browse files
committed
#110 - introduces 'propagateException' property to allow failures in JMS to be ignored or propagated.
Change in behaviour, defaults to false (ie swallow exception if occurs)
1 parent 7d3f32e commit e9e4775

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

modules/spi/publishmq/impl/servicespi/src/main/java/org/isisaddons/module/publishmq/dom/servicespi/PublisherServiceUsingActiveMq.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ public class PublisherServiceUsingActiveMq implements PublisherService {
3636

3737
private static final Logger LOG = LoggerFactory.getLogger(PublisherServiceUsingActiveMq.class);
3838

39-
//region > keys
4039
public static final String ROOT = "isis.services." + PublisherServiceUsingActiveMq.class.getSimpleName() + ".";
4140

4241
public static final String KEY_VM_TRANSPORT_URL = ROOT + "vmTransportUri";
4342
public static final String KEY_VM_TRANSPORT_URL_DEFAULT = "vm://broker";
4443

4544
public static final String KEY_MEMBER_INTERACTIONS_QUEUE = ROOT + "memberInteractionsQueue";
4645
public static final String KEY_MEMBER_INTERACTIONS_QUEUE_DEFAULT = "memberInteractionsQueue";
47-
//endregion
46+
4847
public static final String KEY_ENABLED = ROOT + "enabled";
4948
public static final String KEY_ENABLED_DEFAULT = "true";
5049

51-
//region > fields
50+
public static final String KEY_PROPAGATE_EXCEPTION = ROOT + "propagateException";
51+
public static final String KEY_PROPAGATE_EXCEPTION_DEFAULT = "false";
52+
5253

5354
private ConnectionFactory jmsConnectionFactory;
5455
private Connection jmsConnection;
@@ -59,15 +60,15 @@ public class PublisherServiceUsingActiveMq implements PublisherService {
5960
String memberInteractionsQueueName;
6061

6162
private boolean enabled;
63+
private boolean propagateException;
6264

63-
//endregion
6465

65-
//region > init, shutdown
6666

6767
@PostConstruct
6868
public void init(Map<String,String> properties) {
6969

7070
enabled = properties.getOrDefault(KEY_ENABLED, KEY_ENABLED_DEFAULT).equalsIgnoreCase("true");
71+
propagateException = properties.getOrDefault(KEY_PROPAGATE_EXCEPTION, KEY_PROPAGATE_EXCEPTION_DEFAULT).equalsIgnoreCase("true");
7172

7273
vmTransportUrl = properties.getOrDefault(KEY_VM_TRANSPORT_URL, KEY_VM_TRANSPORT_URL_DEFAULT);
7374
memberInteractionsQueueName = properties.getOrDefault(KEY_MEMBER_INTERACTIONS_QUEUE,
@@ -139,10 +140,8 @@ private static void stopSafely(final BrokerService broker) {
139140
}
140141
}
141142

142-
//endregion
143143

144144

145-
//region > publish (execution)
146145

147146
@Override
148147
public void publish(final Interaction.Execution<?, ?> execution) {
@@ -171,7 +170,7 @@ private void sendUsingJms(final InteractionDto interactionDto) {
171170
try {
172171

173172
session = jmsConnection.createSession(transacted, Session.SESSION_TRANSACTED);
174-
TextMessage message = session.createTextMessage(xml);
173+
final TextMessage message = session.createTextMessage(xml);
175174

176175
final String transactionId = interactionDto.getTransactionId();
177176
final int sequence = interactionDto.getExecution().getSequence();
@@ -188,15 +187,23 @@ private void sendUsingJms(final InteractionDto interactionDto) {
188187
}
189188

190189
final Queue queue = session.createQueue(memberInteractionsQueueName);
191-
MessageProducer producer = session.createProducer(queue);
190+
final MessageProducer producer = session.createProducer(queue);
192191
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
193192
producer.send(message);
194193

195194
session.commit();
196195

197-
} catch (JMSException e) {
196+
} catch (final JMSException ex) {
198197
rollback(session);
199-
throw new ApplicationException("Failed to publish message", e);
198+
if(propagateException) {
199+
throw new ApplicationException(String.format(
200+
"Failed to publish message, and aborting (as per '%s' property)", KEY_PROPAGATE_EXCEPTION),
201+
ex);
202+
} else {
203+
LOG.error(String.format(
204+
"Failed to publish message, but continuing (as per '%s' property)", KEY_PROPAGATE_EXCEPTION),
205+
ex);
206+
}
200207
} finally {
201208
if(session != null) {
202209
closeSafely(session);
@@ -220,9 +227,7 @@ private static void rollback(final Session session) {
220227
// ignore
221228
}
222229
}
223-
//endregion
224230

225-
//region > publish (published objects)
226231

227232
@Override
228233
public void publish(final PublishedObjects publishedObjects) {
@@ -236,9 +241,7 @@ private void persist(final PublishedObjects publishedObjects) {
236241
publishedObjectsRepository.persist(publishedObjects);
237242
}
238243

239-
//endregion
240244

241-
//region > republish
242245
/**
243246
* Private API.
244247
* @param interactionDto
@@ -248,15 +251,12 @@ public void republish(final InteractionDto interactionDto) {
248251
sendUsingJms(interactionDto);
249252
}
250253

251-
//endregion
252254

253255

254-
//region > injected services
255256
@Inject
256-
private PublishedObjectsRepository publishedObjectsRepository;
257+
PublishedObjectsRepository publishedObjectsRepository;
257258

258259
@Inject
259-
private InteractionExecutionRepository interactionExecutionRepository;
260-
//endregion
260+
InteractionExecutionRepository interactionExecutionRepository;
261261

262262
}

0 commit comments

Comments
 (0)