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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
\.idea/
\.vertx/
server/target
*.iml
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
stagemonitor-vertx-example
# Stagemonitor Vertx Example

This project is a example project for the stagemonitor-vertx plugin. The project is very basic it's only a login page and a book search page. The goal is to show how the plugin work in a Vertx environment. This project have a Vertx vanilla version and a version with the Vertx RxJava plugin.

## Usage
To use the plugin correctly you must enter a valid elasticsearch url in stagemonitor.properties.

### Start vanilla version
To start the vanilla version you must run the server module with those config:
- Main Class: io.vertx.core.Starter
- Vm Options: -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory
- Program arguments: run org.stagemonitor.vertx.example.verticles.MainVerticle

### Start RxJava version
To start the vanilla version you must run the server module with those config:
- Main Class: io.vertx.core.Starter
- Vm Options: -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.Log4jLogDelegateFactory
- Program arguments: run org.stagemonitor.vertx.example.verticles.rxjava.MainVerticle

### Use the app
To use the app go on [localhost:8080](http://localhost:8080)

The possible login option are:
- User: test1 Password: test1
- User: test2 Password: test2

The books available are:
- book1
- book2
40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.stagemonitor</groupId>
<artifactId>stagemonitor-vertx-example</artifactId>
<packaging>pom</packaging>
<version>0.1</version>
<modules>
<module>server</module>
</modules>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Set pullInDeps to true if you want any modules specified in the 'includes'
and 'deploys' fields in your mod.json to be automatically pulled in during
packaging and added inside your module. Doing this means your module won't
download and install those dependencies at run-time when they're first requested. -->
<vertx.pullInDeps>false</vertx.pullInDeps>

<!-- Set createFatJar to true if you want to create a fat executable jar
which contains the Vert.x binaries along with the module so it can be run
with java -jar <jarname> -->
<vertx.createFatJar>false</vertx.createFatJar>

<!--Vertx module name -->
<module.name>${project.groupId}~${project.artifactId}~${project.version}</module.name>

<!-- The directory where the module will be assembled - you can override
this on the command line with -Dmods.directory=mydir -->
<mods.directory>target/mods</mods.directory>

<!--Dependency versions -->
<vertx.version>3.0.0</vertx.version>
<vertx.testtools.version>2.0.3-final</vertx.testtools.version>
</properties>
</project>
60 changes: 60 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>stagemonitor-vertx-example</artifactId>
<groupId>org.stagemonitor</groupId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>server</artifactId>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java</artifactId>
<version>${vertx.version}</version>
</dependency>
<dependency>
<groupId>org.stagemonitor</groupId>
<artifactId>stagemonitor-vertx</artifactId>
<version>0.32.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.24</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.stagemonitor.vertx.example;

import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonObject;
import org.stagemonitor.vertx.utils.RequestNamer;

public class RequestNamerImpl implements RequestNamer {
@Override
public String getRequestName(Message<?> message) {
JsonObject body = (JsonObject) message.body();
return message.address() + "." + body.getString("action");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.stagemonitor.vertx.example.database;

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.HashMap;

public class DatabaseStub {
private static DatabaseStub ourInstance = new DatabaseStub();

public static DatabaseStub aquire() {
return ourInstance;
}

private JsonArray acceptedCredentials;
private HashMap<String, JsonObject> books;
private HashMap<String, HashMap<String, Integer>> availabilities;

private DatabaseStub() {
acceptedCredentials = new JsonArray(new ArrayList<JsonObject>(){{
add(new JsonObject(){{
put("username", "test1");
put("password", "test1");
}});
add(new JsonObject(){{
put("username", "test2");
put("password", "test2");
}});
}});

books = new HashMap<String, JsonObject>(){{
put("book1", new JsonObject(){{
put("name", "book1");
put("author", "author1");
put("price", 12.50);
}});
put("book2", new JsonObject(){{
put("name", "book2");
put("author", "author2");
put("price", 15.50);
}});
}};

availabilities = new HashMap<String, HashMap<String, Integer>>(){{
put("Montreal", new HashMap<String, Integer>(){{
put("book1", 2);
put("book2", 3);
}});
put("Laval", new HashMap<String, Integer>(){{
put("book1", 3);
put("book2", 2);
}});
put("Repentigny", new HashMap<String, Integer>(){{
put("book1", 2);
put("book2", 0);
}});
put("Terrebonne", new HashMap<String, Integer>(){{
put("book1", 0);
put("book2", 2);
}});
}};
}

public boolean checkCredentials(String username, String password){
boolean accepted = false;
JsonObject user;
for (int i = 0; i < acceptedCredentials.size() && ! accepted; i++) {
user = acceptedCredentials.getJsonObject(i);
accepted = username.equals(user.getString("username")) && password.equals(user.getString("password"));
}
return accepted;
}

public JsonObject getBookByName(String name){
return books.get(name);
}

public JsonObject getBookAvailabilities(String name){
JsonObject avail = new JsonObject();
int count;
for(String city : availabilities.keySet()){
count = availabilities.get(city).get(name);
if(count > 0){
avail.put(city, count);
}
}
return avail;
}
}
Loading