use of io.gravitee.repository.management.model.Command in project gravitee-management-rest-api by gravitee-io.
the class CommandServiceImpl method ack.
@Override
public void ack(String messageId) {
try {
Optional<Command> optMsg = commandRepository.findById(messageId);
// if not found, this is probably because it has been deleted
if (optMsg.isPresent()) {
Command msg = optMsg.get();
if (msg.getAcknowledgments() == null) {
msg.setAcknowledgments(Collections.singletonList(node.id()));
} else if (!msg.getAcknowledgments().contains(node.id())) {
msg.getAcknowledgments().add(node.id());
}
commandRepository.update(msg);
}
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to acknowledge a message", ex);
}
}
use of io.gravitee.repository.management.model.Command in project gravitee-management-rest-api by gravitee-io.
the class CommandServiceImpl method send.
@Override
public void send(NewCommandEntity messageEntity) {
if (messageEntity.getTo() == null || messageEntity.getTo().isEmpty()) {
throw new Message2RecipientNotFoundException();
}
Command command = new Command();
command.setId(UuidString.generateRandom());
command.setEnvironmentId(GraviteeContext.getCurrentEnvironment());
command.setFrom(node.id());
command.setTo(messageEntity.getTo());
command.setTags(convert(messageEntity.getTags()));
long now = System.currentTimeMillis();
command.setCreatedAt(new Date(now));
command.setUpdatedAt(command.getCreatedAt());
command.setExpiredAt(new Date(now + (messageEntity.getTtlInSeconds() * 1000)));
if (messageEntity.getContent() != null) {
command.setContent(messageEntity.getContent());
}
try {
commandRepository.create(command);
} catch (TechnicalException ex) {
logger.error("An error occurs while trying to create {}", command, ex);
throw new TechnicalManagementException("An error occurs while trying create " + command, ex);
}
}
Aggregations