Skip to content

Instantly share code, notes, and snippets.

View javapro-magazine's full-sized avatar

JAVAPRO javapro-magazine

View GitHub Profile
@HelidonTest
@DisableDiscovery
@AddBean(MyBean.class)
@AddExtension(ConfigCdiExtension.class)
@AddConfig(key = "app.greeting", value = "TestHello")
class TestNoDiscovery {
@Inject
private MyBean myBean;
@Test
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
public static void main(String[] args) throws Exception {
// Ein Handle für gRPC, das eine unäre Methode verwendet. Standardmäßig Java
// serialisieren, serialisieren und deserialisieren.
ClientServiceDescriptor descriptor = ClientServiceDescriptor
.builder(HelloService.class)
.unary("SayHello")
.build();
// Erstelle einen Kanal am Port 1408
public static void main(String[] args) throws Exception {
// Implement the simplest possible gRPC service.
GrpcServer grpcServer = GrpcServer
.create(GrpcRouting.builder()
.register(new HelloService())
.build())
.start()
.toCompletableFuture()
.get(10, TimeUnit.SECONDS);
System.out.println("gRPC Server started at: http://localhost:"
Single.just("1")
.map(Integer::parseInt)
.map(i -> i + 5)
.toStage()
.whenComplete((i, t) -> System.out.println("Result: " + i));
> Result: 6
AtomicInteger sum = new AtomicInteger();
Multi.just("1", "2", "3", "4", "5")
.limit(3)
.map(Integer::parseInt)
.forEach(sum::addAndGet);
System.out.println("Sum: " + sum.get());
> Sum: 6
WebClient client = WebClient.builder()
.baseUri("http://localhost")
.build();
Single<String> response = client.get()
.path("/endpoint")
.request(String.class);
db:
source: "jdbc"
connection:
url: "jdbc:mysql://127.0.0.1:3306/pokemon?useSSL=false"
username: "user"
password: "password"
statements:
ping: "DO 0"
select-all-pokemons: "SELECT id, name FROM Pokemons"
dbClient.execute(exec -> exec
.createUpdate("{\"collection\": \"pokemons\","
+ "\"value\":{$set:{\"name\":$name}},"
+ "\"query\":{id:$id}}")
.addParam("id", 1)
.addParam("name", "Pikachu")
.execute()
);
dbClient.inTransaction(tx -> tx
.createQuery("SELECT name FROM Pokemons WHERE id = :id")
.addParam("id", 1)
.execute()
);