Skip to content

Commit

Permalink
Make listeners explicitly transactional
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Nov 30, 2024
1 parent fa73fef commit fb3d7bb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openwms.wms.movements.impl;

import org.ameba.annotation.Measured;
import org.ameba.exception.NotFoundException;
import org.ameba.i18n.Translator;
import org.openwms.common.location.api.LocationApi;
Expand All @@ -23,6 +24,8 @@
import org.openwms.common.transport.api.messages.TransportUnitMO;
import org.openwms.wms.movements.spi.common.AsyncTransportUnitApi;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

import static org.openwms.wms.movements.MovementsMessages.LOCATION_NOT_FOUND_BY_ERP_CODE;
Expand All @@ -45,7 +48,9 @@ class MovementEventListener {
this.asyncTransportUnitApi = asyncTransportUnitApi;
}

@Measured
@TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onEvent(MovementTargetChangedEvent event) {
var locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
if (locationByErpCode.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openwms.wms.movements.impl;

import org.ameba.annotation.Measured;
import org.openwms.core.SpringProfiles;
import org.openwms.wms.movements.commands.MovementMO;
import org.slf4j.Logger;
Expand All @@ -23,7 +24,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

import static org.openwms.wms.movements.events.api.MovementEvent.Type.CANCELLED;
Expand Down Expand Up @@ -52,7 +54,9 @@ class MovementEventPropagator {
this.amqpTemplate = amqpTemplate;
}

@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Measured
@TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onEvent(MovementEvent event) {
var movement = event.getSource();
var vo = MovementMO.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openwms.wms.movements.impl;

import org.ameba.annotation.Measured;
import org.ameba.annotation.TxService;
import org.openwms.wms.movements.Message;
import org.openwms.wms.movements.MovementProperties;
Expand All @@ -26,7 +27,6 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
Expand All @@ -53,7 +53,8 @@ class PutawayAdapter {
}

@ConditionalOnExpression("${owms.movement.putaway-resolution-enabled}")
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
@Measured
@TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {Exception.class})
public void onEvent(MovementEvent event) {
var movement = event.getSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.openwms.wms.movements.impl;

import org.ameba.annotation.Measured;
import org.ameba.exception.NotFoundException;
import org.ameba.http.ctx.CallContext;
import org.ameba.http.ctx.CallContextHolder;
Expand All @@ -33,6 +34,8 @@
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

import static org.openwms.transactions.api.commands.TransactionCommand.Type.CREATE;
Expand Down Expand Up @@ -66,7 +69,9 @@ class TransactionWriter {
this.asyncTransactionApi = asyncTransactionApi;
}

@Measured
@TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onEvent(MovementEvent event) {
switch (event.getType()) {
case MOVED:
Expand Down Expand Up @@ -108,7 +113,9 @@ public void onEvent(MovementEvent event) {
}
}

@Measured
@TransactionalEventListener
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onEvent(MovementTargetChangedEvent event) {
var locationByErpCode = locationApi.findByErpCode(event.getSource().getTargetLocation());
if (locationByErpCode.isPresent()) {
Expand Down

0 comments on commit fb3d7bb

Please sign in to comment.