Giter Club home page Giter Club logo

quarkus-vertx-chat's Introduction

quarkus-vertx-chat

A rudimentary messaging application showcasing Quarkus, Vert.x, Reactive Streams and server-sent events (SSE).

For some more backround be sure to read the associated article.

Highlights

Creating this project

If you want to start this project from scratch you can like so:

mvn io.quarkus:quarkus-maven-plugin:0.14.0:create \
    -DprojectGroupId=team.quad \
    -DprojectArtifactId=quarkus-vertx-chat \
    -Dextensions="hibernate-validator, resteasy-jsonb, smallrye-openapi, vertx"

Alternatively, extensions can be added one by one after the base project is created:

mvn io.quarkus:quarkus-maven-plugin:0.14.0:create \
    -DprojectGroupId=team.quad \
    -DprojectArtifactId=quarkus-vertx-chat

then

cd quarkus-vertx-chat
./mvnw quarkus:add-extension -Dextensions=resteasy-jsonb
./mvnw quarkus:add-extension -Dextensions=hibernate-validator
./mvnw quarkus:add-extension -Dextensions="smallrye-openapi"
./mvnw quarkus:add-extension -Dextensions=vertx

Start the application

This project ships with the correct version of mvn if you prefer to use that. You may start the project in development mode like so:

./mvnw quarkus:dev

In development mode, Quarkus will recompile and changed files and restart the application on each request.

Functional Testing

Here is an example of a functional test from the set of tests in this repository:

public void testJoinGroupResponse() {
    User user = new User("[email protected]", "Christopher");

    User result =
          given()
            .contentType("application/json")
            .body(user)
            .when().post("/join")
            .as(User.class);

    assertEquals("[email protected]", result.getUsername());
    assertEquals("Christopher", result.getAlias());
}

A JSON binding library will be necessary, such as Jackson, to make use of certain REST-assured features that involve converting JSON to Java objects and vice-versa:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <scope>test</scope>
</dependency>

A simple UI

This version of the application ships with a simple version of the UI for demo purposes and a more elaborate one that is more convenient to use and with more asthetic appeal. The simple version is as follows:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8"/>
    <script type="application/javascript" src="streaming.js"></script>
  </head>
  <body>
    <div id="container"></div>
  </body>
</html>

streaming.js:

var eventSource = new EventSource("/stream");
eventSource.onmessage = function (event) {
    var container = document.getElementById("container");
    var paragraph = document.createElement("p");
    paragraph.innerHTML = event.data;
    container.appendChild(paragraph);
};

quarkus-vertx-chat's People

Contributors

chrisjleu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.