org.springframework.data.mongodb.core.ReactiveMongoTemplate Java Examples

The following examples show how to use org.springframework.data.mongodb.core.ReactiveMongoTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveComapnyApplication.java    From reactive-company with Apache License 2.0 6 votes vote down vote up
@Bean
CommandLineRunner initData(ReactiveMongoTemplate reactiveMongoTemplate, BlogPostRepository blogPostRepository, ProjectRepository projectRepository) {
	return (p) -> {
		reactiveMongoTemplate.dropCollection(BlogPost.class).then(reactiveMongoTemplate.createCollection(
				BlogPost.class, CollectionOptions.empty().capped(104857600).size(104857600))).block();
		
		//blogPostRepository.deleteAll().block();
		blogPostRepository.save(new BlogPost("authorId1", "title1", "content1", "tagString1")).block();
		blogPostRepository.save(new BlogPost("authorId2", "title2", "content2", "tagString2")).block();
		blogPostRepository.save(new BlogPost("authorId3", "title3", "content3", "tagString3")).block();
		blogPostRepository.save(new BlogPost("authorId4", "title4", "content4", "tagString4")).block();

		projectRepository.deleteAll().block();
		projectRepository.save(new Project("name1", "repoUrl1", "siteUrl1", "category1", "description1")).block();
		projectRepository.save(new Project("name2", "repoUrl2", "siteUrl2", "category2", "description2")).block();
		projectRepository.save(new Project("name3", "repoUrl3", "siteUrl3", "category3", "description3")).block();
		projectRepository.save(new Project("name4", "repoUrl4", "siteUrl4", "category4", "description4")).block();
	};
}
 
Example #2
Source File: MongoReactiveDataInitializer.java    From spring-fu with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(GenericApplicationContext context) {
	MongoReactiveDataAutoConfiguration configuration = new MongoReactiveDataAutoConfiguration();
	context.registerBean(MappingMongoConverter.class, () -> configuration.mappingMongoConverter(context.getBean(MongoMappingContext.class), context.getBean(MongoCustomConversions.class)));
	context.registerBean(SimpleReactiveMongoDatabaseFactory.class, () -> configuration.reactiveMongoDatabaseFactory(this.properties, context.getBean(MongoClient.class)));
	context.registerBean(ReactiveMongoTemplate.class, () -> configuration.reactiveMongoTemplate(context.getBean(ReactiveMongoDatabaseFactory.class), context.getBean(MongoConverter.class)));
}
 
Example #3
Source File: MatchDayWebApplication.java    From reactive-matchday with Apache License 2.0 5 votes vote down vote up
@Bean
public ApplicationRunner initialize(final ReactiveMongoTemplate mongoTemplate) {
	return args -> {

		/*
		 * INSERT ALL THE NEEDED TEST DATA (will block)
		 */
		Data.initializeAllData(mongoTemplate);

		/*
		 * INITIALIZATION OF THE MATCH EVENT STREAM
		 */
		final MatchEventAgent matchEventAgent = new MatchEventAgent(mongoTemplate);
		final Flux<MatchEvent> matchEventStream = matchEventAgent.createAgentStream();
		// Subscribe and just let it run (forever)
		matchEventStream.subscribe();

		/*
		 * INITIALIZATION OF THE MATCH COMMENT STREAM
		 */
		final MatchCommentAgent matchCommentAgent = new MatchCommentAgent(mongoTemplate);
		final Flux<MatchComment> matchCommentStream = matchCommentAgent.createAgentStream();
		// Subscribe and just let it run (forever)
		matchCommentStream.subscribe();

	};
}
 
Example #4
Source File: MatchEventInfoRepository.java    From reactive-matchday with Apache License 2.0 5 votes vote down vote up
public MatchEventInfoRepository(
        final PlayerInfoRepository playerInfoRepository,
        final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.playerInfoRepository = playerInfoRepository;
    this.mongoTemplate = mongoTemplate;
}
 
Example #5
Source File: PageableExecutionUtil.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
public static <FEBS> Flux<FEBS> getPages(Query query, QueryRequest request, Class<FEBS> clazz,
                                         ReactiveMongoTemplate template) {
    Sort sort = Sort.by("id").descending();
    if (StringUtils.isNotBlank(request.getField()) && StringUtils.isNotBlank(request.getOrder())) {
        sort = FebsConstant.ORDER_ASC.equals(request.getOrder()) ?
                Sort.by(request.getField()).ascending() :
                Sort.by(request.getField()).descending();
    }
    Pageable pageable = PageRequest.of(request.getPageNum(), request.getPageSize(), sort);
    return template.find(query.with(pageable), clazz);
}
 
Example #6
Source File: TransactionalWalletServiceTest.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@DisplayName("Reactive transactions for data transfer")
@Test
public void testReactiveTransactionalApproach(
   @Autowired WalletRepository walletRepository,
   @Autowired ReactiveMongoTemplate mongoTemplate
) {
   WalletService walletService = new TransactionalWalletService(mongoTemplate, walletRepository);
   Tuple2<Long, Long> expectedActual = simulateOperations(walletService);

   // Whe know that balance should be the same with transactions
   Assert.assertEquals(expectedActual.getT1(), expectedActual.getT2());
}
 
Example #7
Source File: TransactionalWalletService.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
public TransactionalWalletService(
   ReactiveMongoTemplate mongoTemplate,
   WalletRepository walletRepository
) {
   super(walletRepository);
   this.mongoTemplate = mongoTemplate;
}
 
Example #8
Source File: HmlHandler.java    From -Data-Stream-Development-with-Apache-Spark-Kafka-and-Spring-Boot with MIT License 5 votes vote down vote up
public HmlHandler(RsvpsKafkaProducer rsvpsKafkaProducer,
        ReactiveMongoTemplate mongoTemplate,
        DummyBusinessLogic dummyBusinessLogic) {
    this.rsvpsKafkaProducer = rsvpsKafkaProducer;
    this.mongoTemplate = mongoTemplate;
    this.dummyBusinessLogic = dummyBusinessLogic;
}
 
Example #9
Source File: InfoLogsCounterManualTest.java    From tutorials with MIT License 5 votes vote down vote up
private void createCappedCollectionUsingReactiveMongoTemplate(ReactiveMongoTemplate reactiveMongoTemplate) {
    reactiveMongoTemplate.dropCollection(Log.class).block();
    reactiveMongoTemplate.createCollection(Log.class, CollectionOptions.empty()
      .maxDocuments(5)
      .size(1024 * 1024L)
      .capped()).block();
}
 
Example #10
Source File: WarnLogsCounterManualTest.java    From tutorials with MIT License 5 votes vote down vote up
private void createCappedCollectionUsingReactiveMongoTemplate(ReactiveMongoTemplate reactiveMongoTemplate) {
    reactiveMongoTemplate.dropCollection(Log.class).block();
    reactiveMongoTemplate.createCollection(Log.class, CollectionOptions.empty()
      .maxDocuments(5)
      .size(1024 * 1024L)
      .capped()).block();
}
 
Example #11
Source File: MatchEventAgent.java    From reactive-matchday with Apache License 2.0 4 votes vote down vote up
public MatchEventAgent(final ReactiveMongoTemplate mongoTemplate) {
	super();
	this.random = new Random(System.currentTimeMillis());
	this.mongoTemplate = mongoTemplate;
}
 
Example #12
Source File: KyMongoConfig.java    From ClusterDeviceControlPlatform with MIT License 4 votes vote down vote up
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
}
 
Example #13
Source File: MatchCommentAgent.java    From reactive-matchday with Apache License 2.0 4 votes vote down vote up
public MatchCommentAgent(final ReactiveMongoTemplate mongoTemplate) {
	super();
	this.random = new Random(System.currentTimeMillis());
	this.mongoTemplate = mongoTemplate;
}
 
Example #14
Source File: MongoDbRepository.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MongoDbRepository(ReactiveMongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example #15
Source File: MatchInfoRepository.java    From reactive-matchday with Apache License 2.0 4 votes vote down vote up
public MatchInfoRepository(final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.mongoTemplate = mongoTemplate;
}
 
Example #16
Source File: ReactiveMongoConfig.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
}
 
Example #17
Source File: Spring5ReactiveApplication.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public ReactiveMongoTemplate reactiveMongoTemplate() {
    return new ReactiveMongoTemplate(mongoClient, "test");
}
 
Example #18
Source File: PlayerInfoRepository.java    From reactive-matchday with Apache License 2.0 4 votes vote down vote up
public PlayerInfoRepository(final ReactiveMongoTemplate mongoTemplate) {
    super();
    this.mongoTemplate = mongoTemplate;
}
 
Example #19
Source File: Data.java    From reactive-matchday with Apache License 2.0 4 votes vote down vote up
public static void initializeAllData(final ReactiveMongoTemplate mongoTemplate) {
    
    /*
     *  Drop collections, then create them again
     */
    final Mono<Void> initializeCollections =
            mongoTemplate
                    .dropCollection(Team.class)
                    .then(mongoTemplate.dropCollection(Match.class))
                    .then(mongoTemplate.dropCollection(Player.class))
                    .then(mongoTemplate.dropCollection(MatchEvent.class))
                    .then(mongoTemplate.dropCollection(MatchComment.class))
                    .then(mongoTemplate.createCollection(Team.class))
                    .then(mongoTemplate.createCollection(Match.class))
                    .then(mongoTemplate.createCollection(Player.class))
                    .then(mongoTemplate.createCollection(
                            MatchEvent.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then(mongoTemplate.createCollection(
                            MatchComment.class, CollectionOptions.empty().size(104857600).capped())) // max: 100MBytes
                    .then();

    /*
     * Add some test data to the collections: teams and players will come from the
     * utility Data class, but we will generate matches between teams randomly each
     * time the application starts (for the fun of it)
     */
    final Mono<Void> initializeData =
            mongoTemplate
                    // Insert all the teams into the corresponding collection and log
                    .insert(Data.TEAMS, Team.class)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    // Collect all inserted team codes and randomly shuffle the list
                    .map(Team::getCode).collectList().doOnNext(Collections::shuffle)
                    .flatMapMany(list -> Flux.fromIterable(list))
                    // Create groups of two teams and insert a new Match for them
                    .buffer(2).map(twoTeams -> new Match(twoTeams.get(0), twoTeams.get(1)))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .concatMap(match -> mongoTemplate.insert(new MatchEvent(match.getId(), MatchEvent.Type.MATCH_START, null, null)))
                    // Finally insert the players into their corresponding collection
                    .thenMany(Flux.fromIterable(Data.PLAYERS))
                    .flatMap(mongoTemplate::insert)
                    .log(LOGGER_INITIALIZE, Level.FINEST)
                    .then();


    /*
     * Perform the initialization, blocking (that's OK, we are bootstrapping a testing app)
     */
    initializeCollections.then(initializeData).block();
    
}
 
Example #20
Source File: ReactiveMongoDbTestConfiguration.java    From mongodb-aggregate-query-support with Apache License 2.0 4 votes vote down vote up
@Bean
public ReactiveMongoOperations reactiveMongoOperations(MongoClient mongoClient, String dbName) {
  return new ReactiveMongoTemplate(mongoClient, dbName);
}
 
Example #21
Source File: MongoConfig.java    From Spring-5.0-Cookbook with MIT License 4 votes vote down vote up
@Bean		 
public ReactiveMongoTemplate reactiveMongoTemplate() {		    
	return new ReactiveMongoTemplate(mongoClient(), getDatabaseName());		 
}
 
Example #22
Source File: RsvpController.java    From -Data-Stream-Development-with-Apache-Spark-Kafka-and-Spring-Boot with MIT License 4 votes vote down vote up
public RsvpController(ReactiveMongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
}
 
Example #23
Source File: BlockLogServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example #24
Source File: RateLimitRuleServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example #25
Source File: RouteLogServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example #26
Source File: RouteUserServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example #27
Source File: RateLimitLogServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}
 
Example #28
Source File: BlackListServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Autowired(required = false)
public void setTemplate(ReactiveMongoTemplate template) {
    this.template = template;
}