Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Steps:
- Add a configuration property inside you `application.properties` file: `greeting=World`
- Modify `BookmarkResource` to read this configuration property and log it at startup:
- Use `@ConfigProperty` to inject the property inside a `greeting` variable.
- Create a `@PostConstruct` method that log it via `log.info("Hello {}", greeting)` using [SLFJ](https://www.slf4j.org/).
- Create a `@PostConstruct` method that log it via `LOGGER.infof("Hello %s", greeting)` using [Jboss logging](https://docs.jboss.org/jbosslogging/latest/org/jboss/logging/Logger.html).
- Test using `mvn quarkus:dev` you should see `Hello World` in the console.
- Add a new line to `application.properties` file: `%dev.greeting=Dev` this is an override of the same property for the dev profile.
- Test using `mvn quarkus:dev` you should see `Hello Dev` in the console.
Expand Down
2 changes: 1 addition & 1 deletion bookmark-message-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<quarkus.version>0.22.0</quarkus.version>
<quarkus.version>1.0.1.Final</quarkus.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package fr.loicmathieu.bookmarkit;

import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.logging.Logger;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class BookmarkConsumer {

private final Logger log = LoggerFactory.getLogger(BookmarkConsumer.class);
private static final Logger LOG = Logger.getLogger(BookmarkConsumer.class);

@Incoming("bookmarks")
public void process(String bookmark) {
log.info("Indexing a bookmark: {}", bookmark);
LOG.infof("Indexing a bookmark: %s", bookmark);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 17 additions & 13 deletions bookmark-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<quarkus.version>0.26.1</quarkus.version>
<quarkus.version>1.0.1.Final</quarkus.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
Expand Down Expand Up @@ -42,29 +42,32 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<!-- Step 5 dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<!--/ Step 5 dependencies -->
<!-- Step 6 dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-metrics</artifactId>
</dependency>
<!-- Step 5 dependencies -->
<!-- <dependency>-->
<!-- <groupId>io.quarkus</groupId>-->
<!-- <artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>
</dependency>
<!--/ Step 5 dependencies -->
<!-- Step 6 dependencies -->
<!-- <dependency>-->
<!-- <groupId>io.quarkus</groupId>-->
<!-- <artifactId>quarkus-rest-client</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.quarkus</groupId>-->
<!-- <artifactId>quarkus-smallrye-fault-tolerance</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<!--/ Step 6 dependencies -->


Expand All @@ -79,6 +82,7 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<!-- test dependencies-->
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package fr.loicmathieu.bookmarkit;

import org.eclipse.microprofile.health.HealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.Readiness;

@Readiness
public class AppHealthCheck implements HealthCheck {

@Override
public HealthCheckResponse call() {
return HealthCheckResponse.builder().name("bookmark").withData("is", "always").up().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package fr.loicmathieu.bookmarkit;

import javax.enterprise.context.ApplicationScoped;
import io.smallrye.reactive.messaging.annotations.Channel;
import io.smallrye.reactive.messaging.annotations.Emitter;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.faulttolerance.Retry;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Timed;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.logging.Logger;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.transaction.Transactional;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
Expand All @@ -10,8 +22,10 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.List;

Expand All @@ -20,39 +34,81 @@
@Consumes(MediaType.APPLICATION_JSON)
public class BookmarkResource {

private static final Logger LOG = Logger.getLogger(BookmarkResource.class);

@ConfigProperty(name = "greeting")
private String greeting;

@Channel("bookmarks")
private Emitter<Bookmark> emitter;

@RestClient
GeoIpService geoIpService;

@PostConstruct
void init() {
LOG.infof("Hello %s", greeting);
}

@GET
public List<Bookmark> listAll(){
@Operation(summary = "List all bookmarks")
@Counted(name = "listAll.count")
@Timed(name = "listAll.time")
public List<Bookmark> listAll() {
return Bookmark.listAll();
}

@GET
@Path("/{id}")
@Path("{id}")
@Operation(summary = "Get a bookmark")
@Counted(name = "get.count")
@Timed(name = "get.time")
public Bookmark get(@PathParam("id") Long id) {
return Bookmark.findById(id);
}

@POST
@Transactional
public Response create(Bookmark bookmark){
bookmark.persist();
return Response.created(URI.create("/bookmarks/" + bookmark.id)).build();
@Operation(summary = "Create a bookmark")
@Counted(name = "create.count")
@Timed(name = "create.time")
@Retry(maxRetries = 2)
public Response create(@Valid Bookmark bookmark) {
GeoIp geoIp = geoIpService.getIpInfos();
if (geoIp != null) {
bookmark.location = geoIp.city;
bookmark.persist();
this.emitter.send(bookmark);
return Response.status(Response.Status.CREATED).entity(bookmark).build();
} else {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}

@PUT
@Path("/{id}")
@Path("{id}")
@Transactional
public void update(Bookmark bookmark){
Bookmark existing = Bookmark.findById(bookmark.id);
existing.url = bookmark.url;
existing.description = bookmark.description;
existing.title = bookmark.title;
@Operation(summary = "Update a bookmark")
@Counted(name = "update.count")
@Timed(name = "update.time")
public Response update(@Valid Bookmark bookmark, @PathParam("id") Long id, @Context UriInfo uriInfo) {
Bookmark entity = Bookmark.findById(id);
entity.description = bookmark.description;
entity.location = bookmark.location;
entity.title = bookmark.title;
entity.url = bookmark.url;
return Response.created(URI.create(uriInfo.getPath())).build();
}

@DELETE
@Path("/{id}")
@Path("{id}")
@Transactional
public void delete(@PathParam("id")Long id){
Bookmark existing = Bookmark.findById(id);
existing.delete();
@Operation(summary = "Delete a bookmark")
@Counted(name = "delete.count")
@Timed(name = "delete.time")
public Response delete(@PathParam("id") Long id) {
Bookmark bookmark = Bookmark.findById(id);
bookmark.delete();
return Response.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.loicmathieu.bookmarkit;

public class GeoIp {
public String query;
public String status;
public String country;
public String countryCode;
public String region;
public String regionName;
public String city;
public String zip;
public Double lat;
public Double lon;
public String timezone;
public String isp;
public String org;
public String as;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.loicmathieu.bookmarkit;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/geoip")
@RegisterRestClient
public interface GeoIpService {

@GET
@Produces(MediaType.APPLICATION_JSON)
GeoIp getIpInfos();

}
16 changes: 13 additions & 3 deletions bookmark-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
greeting=world
%dev.greeting=Dev
fr.loicmathieu.bookmarkit.GeoIpService/mp-rest/url=http://localhost:8093
# Configures the AMQP broker credentials.
amqp-username=quarkus
amqp-password=quarkus
# Configure the AMQP connector to write to the `bookmark` address
mp.messaging.outgoing.bookmarks.connector=smallrye-amqp
mp.messaging.outgoing.bookmarks.address=bookmarks
mp.messaging.outgoing.bookmarks.durable=true
# Datasource configuration
quarkus.datasource.url=jdbc:postgresql://localhost:5432/bookmarkit
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.username=quarkus
quarkus.datasource.password=quarkus
# drop and create the database at startup (use `update` to only update the schema)
quarkus.datasource.username=sarah
quarkus.datasource.password=connor
# drop and create the database at the startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void metricsTest() {
.get("/metrics/application")
.then()
.statusCode(200)
.body("size()", CoreMatchers.is(10));
.body("size()", CoreMatchers.is(13));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package fr.loicmathieu.bookmarkit;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
class NativeBookmarkObservabilityIT extends BookmarkObservabilityTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fr.loicmathieu.bookmarkit;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
class NativeBookmarkResourceIT extends BookmarkResourceTest {

// Execute the same tests but in native mode.
}

4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ services:
ports:
- "5432:5432"
environment:
- POSTGRES_USER=quarkus
- POSTGRES_PASSWORD=quarkus
- POSTGRES_USER=sarah
- POSTGRES_PASSWORD=connor
- POSTGRES_DB=bookmarkit

artemis:
Expand Down
2 changes: 1 addition & 1 deletion geoip-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<quarkus.version>0.26.1</quarkus.version>
<quarkus.version>1.0.1.Final</quarkus.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down
2 changes: 0 additions & 2 deletions geoip-service/src/main/java/com/lahzouz/bookmarkit/GeoIp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lahzouz.bookmarkit;

public class GeoIp {

public String query;
public String status;
public String country;
Expand All @@ -16,5 +15,4 @@ public class GeoIp {
public String isp;
public String org;
public String as;

}
Loading