本文整理汇总了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));
};
}
示例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());
};
}
示例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;
};
}
示例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)));
}
示例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;
});
});
};
}