Commit 8e41f6aa authored by Enriko Käsper's avatar Enriko Käsper
Browse files

TEIS-810: send Rabbit messages after DB transaction commit.

parent 273a183b
theGroup=ee.sm.ti.teis theGroup=ee.sm.ti.teis
theVersion=0.2.0-SNAPSHOT theVersion=0.2.0-SNAPSHOT
commonsVersion=0.22.0-SNAPSHOT commonsVersion=0.22.1-SNAPSHOT
officeApiGatewayVersion=0.8.0-SNAPSHOT officeApiGatewayVersion=0.8.0-SNAPSHOT
pluginVersion=0.0.18-SNAPSHOT pluginVersion=0.0.18-SNAPSHOT
mapstructVersion=1.3.0.Final mapstructVersion=1.3.0.Final
......
package ee.sm.ti.teis.officials.group.service; package ee.sm.ti.teis.officials.group.service;
import ee.sm.ti.teis.domain.officials.OfficialsGroup; import ee.sm.ti.teis.domain.officials.OfficialsGroup;
import ee.sm.ti.teis.domainrequest.rabbit.SendDomainMessageEvent;
import ee.sm.ti.teis.officials.group.OfficialsGroupCreatedMessage; import ee.sm.ti.teis.officials.group.OfficialsGroupCreatedMessage;
import ee.sm.ti.teis.officials.group.OfficialsGroupDeletedMessage; import ee.sm.ti.teis.officials.group.OfficialsGroupDeletedMessage;
import ee.sm.ti.teis.officials.group.OfficialsGroupUpdatedMessage; import ee.sm.ti.teis.officials.group.OfficialsGroupUpdatedMessage;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class OfficialsGroupNotifyService { public class OfficialsGroupNotifyService {
private final RabbitTemplate msRabbitTemplate; private final ApplicationEventPublisher eventPublisher;
public OfficialsGroupNotifyService(RabbitTemplate msRabbitTemplate) { public OfficialsGroupNotifyService(ApplicationEventPublisher eventPublisher) {
this.msRabbitTemplate = msRabbitTemplate; this.eventPublisher = eventPublisher;
} }
void notifyCreate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) { void notifyCreate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupCreatedMessage requestDTO = new OfficialsGroupCreatedMessage(); OfficialsGroupCreatedMessage requestDTO = new OfficialsGroupCreatedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
void notifyUpdate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) { void notifyUpdate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupUpdatedMessage requestDTO = new OfficialsGroupUpdatedMessage(); OfficialsGroupUpdatedMessage requestDTO = new OfficialsGroupUpdatedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
void notifyDelete(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) { void notifyDelete(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupDeletedMessage requestDTO = new OfficialsGroupDeletedMessage(); OfficialsGroupDeletedMessage requestDTO = new OfficialsGroupDeletedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
} }
package ee.sm.ti.teis.officials.official; package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.domain.officials.OfficialUser; import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.domainrequest.rabbit.SendDomainMessageEvent;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@Service @Service
public class OfficialNotifyService { public class OfficialNotifyService {
private final RabbitTemplate msRabbitTemplate; private final ApplicationEventPublisher eventPublisher;
public OfficialNotifyService(RabbitTemplate msRabbitTemplate) { public OfficialNotifyService(ApplicationEventPublisher eventPublisher) {
this.msRabbitTemplate = msRabbitTemplate; this.eventPublisher = eventPublisher;
} }
void notifyCreate(OfficialUser payload, RequestMetaDTO requestMetaDTO) { void notifyCreate(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialCreatedMessage requestDTO = new OfficialCreatedMessage(); OfficialCreatedMessage requestDTO = new OfficialCreatedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
void notifyUpdate(OfficialUser payload, RequestMetaDTO requestMetaDTO) { void notifyUpdate(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialUpdatedMessage requestDTO = new OfficialUpdatedMessage(); OfficialUpdatedMessage requestDTO = new OfficialUpdatedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
void notifyDelete(OfficialUser payload, RequestMetaDTO requestMetaDTO) { void notifyDelete(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialDeletedMessage requestDTO = new OfficialDeletedMessage(); OfficialDeletedMessage requestDTO = new OfficialDeletedMessage();
requestDTO.setPayload(payload, requestMetaDTO); requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO); eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment