当前位置: 首页>>代码示例>>Java>>正文


Java TopicId类代码示例

本文整理汇总了Java中com.lightbend.lagom.javadsl.pubsub.TopicId的典型用法代码示例。如果您正苦于以下问题:Java TopicId类的具体用法?Java TopicId怎么用?Java TopicId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TopicId类属于com.lightbend.lagom.javadsl.pubsub包,在下文中一共展示了TopicId类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: register

import com.lightbend.lagom.javadsl.pubsub.TopicId; //导入依赖的package包/类
/**
 * Register Cargo service call
 *
 * @return
 */
@Override
public ServiceCall<NotUsed, Cargo, Done> register() {
    return (id, request) -> {
        /* Publish received entity into topic named "Topic" */
        PubSubRef<Cargo> topic = topics.refFor(TopicId.of(Cargo.class, "topic"));
        topic.publish(request);
        log.info("Cargo ID: {}.", request.getId());
        /* Look up the Cargo entity for the given ID. */
        PersistentEntityRef<RegistrationCommand> ref =
                persistentEntityRegistry.refFor(CargoEntity.class, request.getId());
        /* Tell the entity to use the Cargo information in the request. */
        return ref.ask(RegisterCargo.of(request));
    };
}
 
开发者ID:lagom,项目名称:activator-lagom-cargotracker,代码行数:20,代码来源:RegistrationServiceImpl.java

示例2: getLiveRegistrations

import com.lightbend.lagom.javadsl.pubsub.TopicId; //导入依赖的package包/类
/**
 * Get live registrations service call
 *
 * @return
 */
@Override
public ServiceCall<NotUsed, NotUsed, Source<Cargo, ?>> getLiveRegistrations() {
    return (id, req) -> {
        PubSubRef<Cargo> topic = topics.refFor(TopicId.of(Cargo.class, "topic"));
        return CompletableFuture.completedFuture(topic.subscriber());
    };
}
 
开发者ID:lagom,项目名称:activator-lagom-cargotracker,代码行数:13,代码来源:RegistrationServiceImpl.java

示例3: addChirp

import com.lightbend.lagom.javadsl.pubsub.TopicId; //导入依赖的package包/类
@Override
public ServiceCall<Chirp, NotUsed> addChirp(String userId) {
  return chirp -> {
    if (!userId.equals(chirp.getUserId()))
      throw new IllegalArgumentException("UserId " + userId + " did not match userId in " + chirp);
    PubSubRef<Chirp> topic = topics.refFor(TopicId.of(Chirp.class, topicQualifier(userId)));
    topic.publish(chirp);
    CompletionStage<NotUsed> result =
      db.executeWrite("INSERT INTO chirp (userId, uuid, timestamp, message) VALUES (?, ?, ?, ?)",
        chirp.getUserId(), chirp.getUuid(), chirp.getTimestamp().toEpochMilli(),
        chirp.getMessage()).thenApply(done -> NotUsed.getInstance());
    return result;
  };
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:15,代码来源:ChirpServiceImpl.java

示例4: refFor

import com.lightbend.lagom.javadsl.pubsub.TopicId; //导入依赖的package包/类
private PubSubRef<Chirp> refFor(String userId) {
    return pubSub.refFor(TopicId.of(Chirp.class, topicQualifier(userId)));
}
 
开发者ID:lagom,项目名称:lagom-java-chirper-example,代码行数:4,代码来源:ChirpTopicImpl.java

示例5: getLiveChirps

import com.lightbend.lagom.javadsl.pubsub.TopicId; //导入依赖的package包/类
@Override
public ServiceCall<LiveChirpsRequest, Source<Chirp, ?>> getLiveChirps(String userId) {
  return req -> {

    CompletionStage<Source<Chirp, ?>> recentChirpSource =
      recentChirps(req.getUserIds()).thenApply(recentChirps -> {
        List<Source<Chirp, ?>> sources = new ArrayList<>();
        for (String uid : req.getUserIds()) {
          PubSubRef<Chirp> topic = topics.refFor(TopicId.of(Chirp.class, topicQualifier(uid)));
          sources.add(topic.subscriber());
        }
        HashSet<String> users = new HashSet<>(req.getUserIds());
        Source<Chirp, ?> publishedChirps = Source.from(sources).flatMapMerge(sources.size(), s -> s)
                .filter(c -> users.contains(c.getUserId()));

        // We currently ignore the fact that it is possible to get duplicate chirps
        // from the recent and the topic. That can be solved with a de-duplication stage.
        return Source.from(recentChirps).concat(publishedChirps);
      });

    // お気に入りの一覧
    CompletionStage<POrderedSet<String>> favorites = favoriteService.getFavorites(userId).invoke();

    return recentChirpSource.thenApply(source -> { // source: つぶやきのストリーム

      return source.mapAsync(2, chirp -> {
        // TODO: STEP2 - お気に入りされた数を取得
        CompletionStage<Integer> favorCount =
                CompletableFuture.completedFuture(0);

        CompletionStage<Chirp> chirpAppliedFavorite =
          favorites.thenCompose(favs ->
          favorCount.thenApply(count ->
            // お気に入りされている場合は isFavorite を true にする
            // お気に入りされた数を favorCount に設定
            favs.contains(chirp.getUuid())
                    ? chirp.withIsFavorite(true).withFavorCount(count)
                    : chirp.withFavorCount(count)
          ));
        return chirpAppliedFavorite;
      });
    });
  };
}
 
开发者ID:negokaz,项目名称:lagom-hands-on-development,代码行数:45,代码来源:ChirpServiceImpl.java


注:本文中的com.lightbend.lagom.javadsl.pubsub.TopicId类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。