Advertisement
Guest User

quarkus-sample

a guest
Dec 2nd, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.57 KB | Source Code | 0 0
  1. // GreetingResource.java
  2. package org.acme;
  3.  
  4. import io.smallrye.mutiny.Multi;
  5. import jakarta.ws.rs.GET;
  6. import jakarta.ws.rs.Path;
  7. import jakarta.ws.rs.Produces;
  8. import jakarta.ws.rs.core.MediaType;
  9. import org.eclipse.microprofile.rest.client.inject.RestClient;
  10.  
  11. @Path("/hello")
  12. public class GreetingResource {
  13.     @RestClient
  14.     MyRemoteService client;
  15.  
  16.     @GET
  17.     @Produces(MediaType.TEXT_PLAIN)
  18.     public Multi<MyRemoteService.TestDTO> hello() {
  19.         return client.getTest()
  20.                      .onItem().invoke(i -> System.out.println(i));
  21.     }
  22. }
  23.  
  24.  
  25. // MyRemoteService.java
  26. package org.acme;
  27.  
  28. import io.smallrye.mutiny.Multi;
  29. import jakarta.ws.rs.GET;
  30. import jakarta.ws.rs.Path;
  31. import jakarta.ws.rs.core.MediaType;
  32. import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
  33. import org.jboss.resteasy.reactive.RestStreamElementType;
  34.  
  35. @RegisterRestClient(baseUri = "http://localhost:5000/api")
  36. public interface MyRemoteService {
  37.  
  38.     @GET
  39.     @Path("/test")
  40.     @RestStreamElementType(MediaType.APPLICATION_JSON)
  41.     Multi<TestDTO> getTest();
  42.  
  43.     record TestDTO(String a) {}
  44. }
  45.  
  46.  
  47. // pom.xml
  48. <?xml version="1.0" encoding="UTF-8"?>
  49. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  50.     <modelVersion>4.0.0</modelVersion>
  51.     <groupId>org.acme</groupId>
  52.     <artifactId>code-with-quarkus</artifactId>
  53.     <version>1.0.0-SNAPSHOT</version>
  54.  
  55.     <properties>
  56.         <compiler-plugin.version>3.13.0</compiler-plugin.version>
  57.         <maven.compiler.release>17</maven.compiler.release>
  58.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  59.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  60.         <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
  61.         <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
  62.         <quarkus.platform.version>3.17.2</quarkus.platform.version>
  63.         <skipITs>true</skipITs>
  64.         <surefire-plugin.version>3.5.0</surefire-plugin.version>
  65.     </properties>
  66.  
  67.     <dependencyManagement>
  68.         <dependencies>
  69.             <dependency>
  70.                 <groupId>${quarkus.platform.group-id}</groupId>
  71.                 <artifactId>${quarkus.platform.artifact-id}</artifactId>
  72.                 <version>${quarkus.platform.version}</version>
  73.                 <type>pom</type>
  74.                 <scope>import</scope>
  75.             </dependency>
  76.         </dependencies>
  77.     </dependencyManagement>
  78.  
  79.     <dependencies>
  80.         <dependency>
  81.             <groupId>io.quarkus</groupId>
  82.             <artifactId>quarkus-rest</artifactId>
  83.         </dependency>
  84.         <dependency>
  85.             <groupId>io.quarkus</groupId>
  86.             <artifactId>quarkus-rest-client-jackson</artifactId>
  87.         </dependency>
  88.         <dependency>
  89.             <groupId>io.quarkus</groupId>
  90.             <artifactId>quarkus-rest-client</artifactId>
  91.         </dependency>
  92.         <dependency>
  93.             <groupId>io.quarkus</groupId>
  94.             <artifactId>quarkus-rest-jackson</artifactId>
  95.         </dependency>
  96.         <dependency>
  97.             <groupId>io.quarkus</groupId>
  98.             <artifactId>quarkus-arc</artifactId>
  99.         </dependency>
  100.         <dependency>
  101.             <groupId>io.quarkus</groupId>
  102.             <artifactId>quarkus-junit5</artifactId>
  103.             <scope>test</scope>
  104.         </dependency>
  105.         <dependency>
  106.             <groupId>io.rest-assured</groupId>
  107.             <artifactId>rest-assured</artifactId>
  108.             <scope>test</scope>
  109.         </dependency>
  110.     </dependencies>
  111.  
  112.     <build>
  113.         <plugins>
  114.             <plugin>
  115.                 <groupId>${quarkus.platform.group-id}</groupId>
  116.                 <artifactId>quarkus-maven-plugin</artifactId>
  117.                 <version>${quarkus.platform.version}</version>
  118.                 <extensions>true</extensions>
  119.                 <executions>
  120.                     <execution>
  121.                         <goals>
  122.                             <goal>build</goal>
  123.                             <goal>generate-code</goal>
  124.                             <goal>generate-code-tests</goal>
  125.                             <goal>native-image-agent</goal>
  126.                         </goals>
  127.                     </execution>
  128.                 </executions>
  129.             </plugin>
  130.             <plugin>
  131.                 <artifactId>maven-compiler-plugin</artifactId>
  132.                 <version>${compiler-plugin.version}</version>
  133.                 <configuration>
  134.                     <parameters>true</parameters>
  135.                 </configuration>
  136.             </plugin>
  137.             <plugin>
  138.                 <artifactId>maven-surefire-plugin</artifactId>
  139.                 <version>${surefire-plugin.version}</version>
  140.                 <configuration>
  141.                     <systemPropertyVariables>
  142.                         <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
  143.                         <maven.home>${maven.home}</maven.home>
  144.                     </systemPropertyVariables>
  145.                 </configuration>
  146.             </plugin>
  147.             <plugin>
  148.                 <artifactId>maven-failsafe-plugin</artifactId>
  149.                 <version>${surefire-plugin.version}</version>
  150.                 <executions>
  151.                     <execution>
  152.                         <goals>
  153.                             <goal>integration-test</goal>
  154.                             <goal>verify</goal>
  155.                         </goals>
  156.                     </execution>
  157.                 </executions>
  158.                 <configuration>
  159.                     <systemPropertyVariables>
  160.                         <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
  161.                         <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
  162.                         <maven.home>${maven.home}</maven.home>
  163.                     </systemPropertyVariables>
  164.                 </configuration>
  165.             </plugin>
  166.         </plugins>
  167.     </build>
  168.  
  169.     <profiles>
  170.         <profile>
  171.             <id>native</id>
  172.             <activation>
  173.                 <property>
  174.                     <name>native</name>
  175.                 </property>
  176.             </activation>
  177.             <properties>
  178.                 <skipITs>false</skipITs>
  179.                 <quarkus.native.enabled>true</quarkus.native.enabled>
  180.             </properties>
  181.         </profile>
  182.     </profiles>
  183. </project>
  184.  
  185.  
Tags: Java quarkus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement