Skip to content

Instantly share code, notes, and snippets.

@aytekin
Created November 18, 2021 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aytekin/f0e545249b255b640ea48a57779e52ef to your computer and use it in GitHub Desktop.
Save aytekin/f0e545249b255b640ea48a57779e52ef to your computer and use it in GitHub Desktop.
reactor-kafka
@Service
@Slf4j
@AllArgsConstructor
public class UserService {
private final KafkaProducer kafkaProducer;
private static final String USER_TOPIC = "user-create";
public Mono<String> userCreate(Mono<UserDto> username){
return username.flatMap(name ->
kafkaProducer.kafkaSender()
.send(USER_TOPIC, name.getUsername())
.doOnNext(voidSenderResult -> log.info("{} sent to {} topic", name.getUsername(), USER_TOPIC))
.doOnNext(voidSenderResult -> log.info("{}", voidSenderResult.recordMetadata()))
.thenReturn("It was sent successfully")
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment