use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageServiceWithCacheTest method assembleReleaseMsg.
private ReleaseMessage assembleReleaseMsg(long id, String msgContent) {
ReleaseMessage msg = new ReleaseMessage(msgContent);
msg.setId(id);
return msg;
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageServiceWithCacheTest method testWhenHasReleaseMsgAndHasRepeatMsg.
@Test
public void testWhenHasReleaseMsgAndHasRepeatMsg() throws Exception {
String someMsgContent = "msg1";
ReleaseMessage someMsg = assembleReleaseMsg(1, someMsgContent);
String anotherMsgContent = "msg2";
ReleaseMessage anotherMsg = assembleReleaseMsg(2, anotherMsgContent);
ReleaseMessage anotherRepeatMsg = assembleReleaseMsg(3, anotherMsgContent);
when(releaseMessageRepository.findFirst500ByIdGreaterThanOrderByIdAsc(0L)).thenReturn(Arrays.asList(someMsg, anotherMsg, anotherRepeatMsg));
releaseMessageServiceWithCache.afterPropertiesSet();
verify(bizConfig).releaseMessageCacheScanInterval();
ReleaseMessage latestReleaseMsg = releaseMessageServiceWithCache.findLatestReleaseMessageForMessages(Sets.newHashSet(someMsgContent, anotherMsgContent));
assertNotNull(latestReleaseMsg);
assertEquals(3, latestReleaseMsg.getId());
assertEquals(anotherMsgContent, latestReleaseMsg.getMessage());
List<ReleaseMessage> latestReleaseMsgGroupByMsgContent = releaseMessageServiceWithCache.findLatestReleaseMessagesGroupByMessages(Sets.newLinkedHashSet(Arrays.asList(someMsgContent, anotherMsgContent)));
assertEquals(2, latestReleaseMsgGroupByMsgContent.size());
assertEquals(3, latestReleaseMsgGroupByMsgContent.get(1).getId());
assertEquals(anotherMsgContent, latestReleaseMsgGroupByMsgContent.get(1).getMessage());
assertEquals(1, latestReleaseMsgGroupByMsgContent.get(0).getId());
assertEquals(someMsgContent, latestReleaseMsgGroupByMsgContent.get(0).getMessage());
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class ReleaseMessageScanner method recordMissingReleaseMessageIds.
private void recordMissingReleaseMessageIds(List<ReleaseMessage> messages, long startId) {
for (ReleaseMessage message : messages) {
long currentId = message.getId();
if (currentId - startId > 1) {
for (long i = startId + 1; i < currentId; i++) {
missingReleaseMessages.putIfAbsent(i, 1);
}
}
startId = currentId;
}
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class DatabaseMessageSender method cleanMessage.
private void cleanMessage(Long id) {
// double check in case the release message is rolled back
ReleaseMessage releaseMessage = releaseMessageRepository.findById(id).orElse(null);
if (releaseMessage == null) {
return;
}
boolean hasMore = true;
while (hasMore && !Thread.currentThread().isInterrupted()) {
List<ReleaseMessage> messages = releaseMessageRepository.findFirst100ByMessageAndIdLessThanOrderByIdAsc(releaseMessage.getMessage(), releaseMessage.getId());
releaseMessageRepository.deleteAll(messages);
hasMore = messages.size() == 100;
messages.forEach(toRemove -> Tracer.logEvent(String.format("ReleaseMessage.Clean.%s", toRemove.getMessage()), String.valueOf(toRemove.getId())));
}
}
use of com.ctrip.framework.apollo.biz.entity.ReleaseMessage in project apollo by ctripcorp.
the class DatabaseMessageSender method sendMessage.
@Override
@Transactional
public void sendMessage(String message, String channel) {
logger.info("Sending message {} to channel {}", message, channel);
if (!Objects.equals(channel, Topics.APOLLO_RELEASE_TOPIC)) {
logger.warn("Channel {} not supported by DatabaseMessageSender!", channel);
return;
}
Tracer.logEvent("Apollo.AdminService.ReleaseMessage", message);
Transaction transaction = Tracer.newTransaction("Apollo.AdminService", "sendMessage");
try {
ReleaseMessage newMessage = releaseMessageRepository.save(new ReleaseMessage(message));
toClean.offer(newMessage.getId());
transaction.setStatus(Transaction.SUCCESS);
} catch (Throwable ex) {
logger.error("Sending message to database failed", ex);
transaction.setStatus(ex);
throw ex;
} finally {
transaction.complete();
}
}
Aggregations