Skip to content

Question regarding Reactor 3 #6

@petivagyok16

Description

@petivagyok16

I know this is kind of irrelevant here, but i don't know any other channel to ask Reactor 3 questions. If you know a place i can ask my question feel free to share :)

So, i'd like to refactor my code, which consists of 3 Publishers (ReactiveMongoRepository responses), and i need all the responses from the repository in the same context to make calculations on them. Other difficulty is that 1 of the publisher is not the same type as the others (2 Mono, 1 Mono). How can i compose these publishers into one single stream in a form that i can access all the three values?

One more thing: does it make any sense to use .publishOn(Schedulers.parallel()) at all the three repository requests?

It looks like this:

return this.userRepository.findById(raterUserId)
	.publishOn(Schedulers.parallel())
	.flatMap(raterUser -> Mono.just(raterUser)
	.then(
		this.messageRepository.findById(messageId)
		.publishOn(Schedulers.parallel())
	        .single()
		.doOnError(this::messageNotFound)
		.flatMap(ratedMessage -> this.userRepository.findById(ratedMessage.getUserId())
								.publishOn(Schedulers.parallel())
								.flatMap(messageOwner -> { ... }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions