pl.allegro.tech.hermes.common.message.undelivered.ZookeeperUndeliveredMessageLog类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中pl.allegro.tech.hermes.common.message.undelivered.ZookeeperUndeliveredMessageLog类的一些代码示例,展示了ZookeeperUndeliveredMessageLog类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZookeeperUndeliveredMessageLog类的具体详情如下:
包路径:pl.allegro.tech.hermes.common.message.undelivered.ZookeeperUndeliveredMessageLog
类名称:ZookeeperUndeliveredMessageLog

ZookeeperUndeliveredMessageLog介绍

暂无

代码示例

代码示例来源:origin: allegro/hermes

@Override
public UndeliveredMessageLog provide() {
  return new ZookeeperUndeliveredMessageLog(zookeeper, paths, mapper);
}

代码示例来源:origin: allegro/hermes

@Override
public void persist() {
  for (SubscriptionName key : lastUndeliveredMessages.keySet()) {
    log(lastUndeliveredMessages.remove(key));
  }
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldNotAddUndeliveredMessageLogToNonExistingSubscriptionPath() {
  // given
  log.add(createUndeliveredMessage("unknownSubscription", "message"));
  log.persist();
  // when
  Optional<SentMessageTrace> result = log.last(TOPIC, "unknownSubscription");
  // then
  assertThat(result.isPresent()).isFalse();
}

代码示例来源:origin: allegro/hermes

@Override
public Optional<SentMessageTrace> last(TopicName topicName, String subscriptionName) {
  try {
    String path = paths.subscriptionPath(topicName, subscriptionName, NODE_NAME);
    if (exists(path)) {
      return Optional.of(mapper.readValue(curator.getData().forPath(path), SentMessageTrace.class));
    } else {
      return Optional.empty();
    }
  } catch (Exception e) {
    throw new InternalProcessingException(
        format("Could not read latest undelivered message for topic: %s and subscription: %s .",
            topicName.qualifiedName(), subscriptionName),
        e);
  }
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldReturnAbsentIfThereAreNoUndeliveredMessagesForGivenSubscription() {
  // when
  Optional<SentMessageTrace> result = log.last(new TopicName("unknown", "topic"), "subscription");
  // then
  assertThat(result.isPresent()).isFalse();
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldAddUndeliveredMessageToLog() throws Exception {
  // given when
  log.add(createUndeliveredMessage(SUBSCRIPTION, "message"));
  log.persist();
  // then
  SentMessageTrace lastMessage = log.last(TOPIC, "subscription").get();
  assertThat(lastMessage.getMessage()).isEqualTo("message");
}

代码示例来源:origin: allegro/hermes

private void log(SentMessageTrace messageTrace) {
  try {
    String undeliveredPath = paths.subscriptionPath(messageTrace.getTopicName(), messageTrace.getSubscription(), NODE_NAME);
    BackgroundPathAndBytesable<?> builder = exists(undeliveredPath) ? curator.setData() : curator.create();
    builder.forPath(undeliveredPath, mapper.writeValueAsBytes(messageTrace));
  } catch (Exception exception) {
    LOGGER.warn(
        format("Could not log undelivered message for topic: %s and subscription: %s",
            messageTrace.getQualifiedTopicName(),
            messageTrace.getSubscription()
        ),
        exception
    );
  }
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldReturnLatestUndeliveredMessage() throws Exception {
  // given
  log.add(createUndeliveredMessage(SUBSCRIPTION, "old message"));
  log.add(createUndeliveredMessage(SUBSCRIPTION, "new message"));
  log.persist();
  // when
  SentMessageTrace lastMessage = log.last(TOPIC, "subscription").get();
  // then
  assertThat(lastMessage.getMessage()).isEqualTo("new message");
}

代码示例来源:origin: allegro/hermes

@Bean
UndeliveredMessageLog undeliveredMessageLog() {
  return new ZookeeperUndeliveredMessageLog(storageZookeeper(), zookeeperPaths(), objectMapper);
}

相关文章