@@ -36,19 +36,20 @@ public class PublisherServiceUsingActiveMq implements PublisherService {
36
36
37
37
private static final Logger LOG = LoggerFactory .getLogger (PublisherServiceUsingActiveMq .class );
38
38
39
- //region > keys
40
39
public static final String ROOT = "isis.services." + PublisherServiceUsingActiveMq .class .getSimpleName () + "." ;
41
40
42
41
public static final String KEY_VM_TRANSPORT_URL = ROOT + "vmTransportUri" ;
43
42
public static final String KEY_VM_TRANSPORT_URL_DEFAULT = "vm://broker" ;
44
43
45
44
public static final String KEY_MEMBER_INTERACTIONS_QUEUE = ROOT + "memberInteractionsQueue" ;
46
45
public static final String KEY_MEMBER_INTERACTIONS_QUEUE_DEFAULT = "memberInteractionsQueue" ;
47
- //endregion
46
+
48
47
public static final String KEY_ENABLED = ROOT + "enabled" ;
49
48
public static final String KEY_ENABLED_DEFAULT = "true" ;
50
49
51
- //region > fields
50
+ public static final String KEY_PROPAGATE_EXCEPTION = ROOT + "propagateException" ;
51
+ public static final String KEY_PROPAGATE_EXCEPTION_DEFAULT = "false" ;
52
+
52
53
53
54
private ConnectionFactory jmsConnectionFactory ;
54
55
private Connection jmsConnection ;
@@ -59,15 +60,15 @@ public class PublisherServiceUsingActiveMq implements PublisherService {
59
60
String memberInteractionsQueueName ;
60
61
61
62
private boolean enabled ;
63
+ private boolean propagateException ;
62
64
63
- //endregion
64
65
65
- //region > init, shutdown
66
66
67
67
@ PostConstruct
68
68
public void init (Map <String ,String > properties ) {
69
69
70
70
enabled = properties .getOrDefault (KEY_ENABLED , KEY_ENABLED_DEFAULT ).equalsIgnoreCase ("true" );
71
+ propagateException = properties .getOrDefault (KEY_PROPAGATE_EXCEPTION , KEY_PROPAGATE_EXCEPTION_DEFAULT ).equalsIgnoreCase ("true" );
71
72
72
73
vmTransportUrl = properties .getOrDefault (KEY_VM_TRANSPORT_URL , KEY_VM_TRANSPORT_URL_DEFAULT );
73
74
memberInteractionsQueueName = properties .getOrDefault (KEY_MEMBER_INTERACTIONS_QUEUE ,
@@ -139,10 +140,8 @@ private static void stopSafely(final BrokerService broker) {
139
140
}
140
141
}
141
142
142
- //endregion
143
143
144
144
145
- //region > publish (execution)
146
145
147
146
@ Override
148
147
public void publish (final Interaction .Execution <?, ?> execution ) {
@@ -171,7 +170,7 @@ private void sendUsingJms(final InteractionDto interactionDto) {
171
170
try {
172
171
173
172
session = jmsConnection .createSession (transacted , Session .SESSION_TRANSACTED );
174
- TextMessage message = session .createTextMessage (xml );
173
+ final TextMessage message = session .createTextMessage (xml );
175
174
176
175
final String transactionId = interactionDto .getTransactionId ();
177
176
final int sequence = interactionDto .getExecution ().getSequence ();
@@ -188,15 +187,23 @@ private void sendUsingJms(final InteractionDto interactionDto) {
188
187
}
189
188
190
189
final Queue queue = session .createQueue (memberInteractionsQueueName );
191
- MessageProducer producer = session .createProducer (queue );
190
+ final MessageProducer producer = session .createProducer (queue );
192
191
producer .setDeliveryMode (DeliveryMode .PERSISTENT );
193
192
producer .send (message );
194
193
195
194
session .commit ();
196
195
197
- } catch (JMSException e ) {
196
+ } catch (final JMSException ex ) {
198
197
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
+ }
200
207
} finally {
201
208
if (session != null ) {
202
209
closeSafely (session );
@@ -220,9 +227,7 @@ private static void rollback(final Session session) {
220
227
// ignore
221
228
}
222
229
}
223
- //endregion
224
230
225
- //region > publish (published objects)
226
231
227
232
@ Override
228
233
public void publish (final PublishedObjects publishedObjects ) {
@@ -236,9 +241,7 @@ private void persist(final PublishedObjects publishedObjects) {
236
241
publishedObjectsRepository .persist (publishedObjects );
237
242
}
238
243
239
- //endregion
240
244
241
- //region > republish
242
245
/**
243
246
* Private API.
244
247
* @param interactionDto
@@ -248,15 +251,12 @@ public void republish(final InteractionDto interactionDto) {
248
251
sendUsingJms (interactionDto );
249
252
}
250
253
251
- //endregion
252
254
253
255
254
- //region > injected services
255
256
@ Inject
256
- private PublishedObjectsRepository publishedObjectsRepository ;
257
+ PublishedObjectsRepository publishedObjectsRepository ;
257
258
258
259
@ Inject
259
- private InteractionExecutionRepository interactionExecutionRepository ;
260
- //endregion
260
+ InteractionExecutionRepository interactionExecutionRepository ;
261
261
262
262
}
0 commit comments