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
theVersion=0.2.0-SNAPSHOT
commonsVersion=0.22.0-SNAPSHOT
commonsVersion=0.22.1-SNAPSHOT
officeApiGatewayVersion=0.8.0-SNAPSHOT
pluginVersion=0.0.18-SNAPSHOT
mapstructVersion=1.3.0.Final
......
package ee.sm.ti.teis.officials.group.service;
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.OfficialsGroupDeletedMessage;
import ee.sm.ti.teis.officials.group.OfficialsGroupUpdatedMessage;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
@Service
public class OfficialsGroupNotifyService {
private final RabbitTemplate msRabbitTemplate;
private final ApplicationEventPublisher eventPublisher;
public OfficialsGroupNotifyService(RabbitTemplate msRabbitTemplate) {
this.msRabbitTemplate = msRabbitTemplate;
public OfficialsGroupNotifyService(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
void notifyCreate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupCreatedMessage requestDTO = new OfficialsGroupCreatedMessage();
requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO);
eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
}
void notifyUpdate(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupUpdatedMessage requestDTO = new OfficialsGroupUpdatedMessage();
requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO);
eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
}
void notifyDelete(OfficialsGroup payload, RequestMetaDTO requestMetaDTO) {
OfficialsGroupDeletedMessage requestDTO = new OfficialsGroupDeletedMessage();
requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO);
eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
}
}
package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.domainrequest.rabbit.SendDomainMessageEvent;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
@Service
public class OfficialNotifyService {
private final RabbitTemplate msRabbitTemplate;
private final ApplicationEventPublisher eventPublisher;
public OfficialNotifyService(RabbitTemplate msRabbitTemplate) {
this.msRabbitTemplate = msRabbitTemplate;
public OfficialNotifyService(ApplicationEventPublisher eventPublisher) {
this.eventPublisher = eventPublisher;
}
void notifyCreate(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialCreatedMessage requestDTO = new OfficialCreatedMessage();
requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO);
eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
}
void notifyUpdate(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialUpdatedMessage requestDTO = new OfficialUpdatedMessage();
requestDTO.setPayload(payload, requestMetaDTO);
msRabbitTemplate.convertAndSend(requestDTO.routingKey(), requestDTO);
eventPublisher.publishEvent(new SendDomainMessageEvent(requestDTO));
}
void notifyDelete(OfficialUser payload, RequestMetaDTO requestMetaDTO) {
OfficialDeletedMessage requestDTO = new OfficialDeletedMessage();
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