This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.rsocket.client; | |
import io.rsocket.AbstractRSocket; | |
import io.rsocket.Payload; | |
import org.reactivestreams.Publisher; | |
import reactor.core.Disposable; | |
import reactor.core.publisher.Flux; | |
import reactor.core.publisher.Mono; | |
public class LoadBalancedRSocket extends AbstractRSocket { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.netifi.demo; | |
import io.rsocket.AbstractRSocket; | |
import io.rsocket.Payload; | |
import io.rsocket.RSocket; | |
import io.rsocket.RSocketFactory; | |
import io.rsocket.transport.netty.client.TcpClientTransport; | |
import io.rsocket.transport.netty.server.TcpServerTransport; | |
import io.rsocket.util.DefaultPayload; | |
import reactor.core.publisher.Flux; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netifi.rsocket.example; | |
import io.rsocket.Payload; | |
import io.rsocket.RSocket; | |
import io.rsocket.RSocketFactory; | |
import io.rsocket.transport.netty.client.TcpClientTransport; | |
import io.rsocket.util.DefaultPayload; | |
import reactor.core.publisher.Flux; | |
public class Client { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class EmployeeRepository { | |
private Database db; | |
public EmployeeRepository() throws Exception { | |
Connection connection = DriverManager.getConnection("jdbc:h2:./build/mydatabase", "sa", "sa"); | |
NonBlockingConnectionPool pool = | |
Pools.nonBlocking() | |
.maxPoolSize(Runtime.getRuntime().availableProcessors() * 5) | |
.connectionProvider(ConnectionProvider.from(connection)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class EmployeeHandler { | |
private final EmployeeRepository repository; | |
public EmployeeHandler(EmployeeRepository repository) { | |
this.repository = repository; | |
} | |
public Mono<ServerResponse> getAllEmployees(ServerRequest request) { | |
Flux<Employee> employees = repository.getAllEmployees(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class EmployeeRouter { | |
@Bean | |
public RouterFunction<ServerResponse> route(EmployeeHandler handler) { | |
return RouterFunctions.route( | |
GET("/employees").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), | |
handler::getAllEmployees) | |
.andRoute( | |
GET("/employee/fn/{fn}/ln/{ln}") | |
.and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netifi.reactor; | |
import reactor.core.publisher.Flux; | |
import reactor.core.publisher.Mono; | |
import reactor.core.scheduler.Schedulers; | |
import java.util.Arrays; | |
public class AsyncCountEvenOrOdd { | |
public static void main(String... args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netifi.jdk; | |
import java.util.Arrays; | |
public class CountEvenOrOdd { | |
public static void main(String... args) { | |
int even = 0; | |
int odd = 0; | |
for (int n : Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) { | |
if (n % 2 == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netifi.reactor; | |
import reactor.core.publisher.Flux; | |
import reactor.core.publisher.Mono; | |
import java.util.Arrays; | |
public class AsynchEvenOrOdd { | |
public static void main(String... args) { | |
Flux.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.netifi.reactor; | |
import reactor.core.publisher.Flux; | |
import java.util.Arrays; | |
public class EvenOrOdd { | |
public static void main(String... args) { | |
Flux.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) | |
.map(EvenOrOdd::check) |
NewerOlder