+ added Message handling for RabbitMQ

This commit is contained in:
Johannes Theiner 2017-04-14 11:02:35 +02:00
parent eaee16f9b0
commit b67ec43f5f
11 changed files with 199 additions and 13 deletions

View File

@ -1,7 +1,7 @@
image: maven:3-jdk-8
build:
script: "mvn clean package --settings .gitlab/settings.xml"
script: "mvn clean install deploy site:deploy --settings .gitlab/settings.xml"
artifacts:
name: "Commons"
paths:

View File

@ -3,7 +3,7 @@
<server>
<id>univentoEU</id>
<username>download</username>
<password>PLCtNT3GEM43bvBc2mRvQMsYe!0JtB</password>
<password>${env.password}</password>
</server>
</servers>

View File

@ -55,5 +55,6 @@
<orderEntry type="library" name="Maven: com.github.nsp:JSkills:master-0.9.0-g8b333ec-15" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.gitlab:java-gitlab-api:1.2.7" level="project" />
</component>
</module>

82
pom.xml
View File

@ -7,9 +7,79 @@
<version>1.0-SNAPSHOT</version>
<name>univento.eu Common Code</name>
<inceptionYear>2016</inceptionYear>
<description>Das Commons Modul stellt alles zur Verfügung was von allen anderen Modulen benötigt wird, wie etwa Datenbank Zugriffe</description>
<url>https://development.univento.eu/docs/Commons</url>
<organization>
<name>univentoEU</name>
<url>https://univento.eu</url>
</organization>
<developers>
<developer>
<id>joethei</id>
<name>Johannes Theiner</name>
<email>joethei@univento.eu</email>
<url>https://joethei.de</url>
<organization>univentoEU</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>Europe/Berlin</timezone>
<properties>
<picUrl>https://de.gravatar.com/userimage/65052389/84435a829d76e6b6c48d67cdd463c6ab.png?size=300</picUrl>
</properties>
</developer>
</developers>
<issueManagement>
<system>gitlab</system>
<url>https://development.univento.eu/issues/Commons</url>
</issueManagement>
<ciManagement>
<system>gitlab</system>
<url>https://development.univento.eu/ci/Commons</url>
</ciManagement>
<distributionManagement>
<repository>
<id>univentoEU</id>
<url>https://development.univento.eu/maven/repositories/univento</url>
</repository>
<site>
<id>univento.commons</id>
<name>univento Commons</name>
<url>sftp://development.univento.eu/doc/Commons</url>
</site>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.enforcer</groupId>
<artifactId>enforcer</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireNoRepositories/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -45,13 +115,6 @@
</plugins>
</build>
<distributionManagement>
<repository>
<id>univentoEU</id>
<url>http://play.univento.eu:8081/repository/univento/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
@ -139,5 +202,10 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gitlab</groupId>
<artifactId>java-gitlab-api</artifactId>
<version>1.2.7</version>
</dependency>
</dependencies>
</project>

View File

@ -9,7 +9,7 @@ import lombok.Getter;
/**
* @author joethei
* @version 1.0
* @version 1.1
*/
@Getter

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.commons.event;
/**
* @author joethei
* @version 0.1
*/
public interface MessageEvent {
void onMessageReceived(String queue, String message);
void onMessageSend(String queue, String message);
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.commons.messaging;
import eu.univento.commons.Commons;
import eu.univento.commons.event.MessageEvent;
import io.vertx.core.json.JsonObject;
import java.util.ArrayList;
import java.util.List;
/**
* @author joethei
* @version 1.0
*/
public class MessageHandler {
private static List<MessageEvent> events = new ArrayList<>();
public static void registerListener(String queue, MessageEvent event) {
events.add(event);
Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicConsume(queue, "univento." + queue, res -> {
if(!res.succeeded()) res.cause().printStackTrace();
});
Commons.getCommons().getVertx().eventBus().consumer(queue, msg -> {
JsonObject json = (JsonObject) msg.body();
event.onMessageReceived(queue, json.getString("body"));
});
}
public static void sendMessage(String queue, String message) {
Commons.getCommons().getMessagingManager().getRabbitMQ().getClient().basicPublish("", queue, new JsonObject().put("body", message), res -> {
if(res.succeeded()) {
for(MessageEvent event : events) {
event.onMessageSend(queue, message);
}
}else res.cause().printStackTrace();
});
}
}

View File

@ -11,7 +11,7 @@ import lombok.Getter;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class MessagingManager {

View File

@ -12,7 +12,7 @@ import lombok.Getter;
/**
* @author joethei
* @version 0.1
* @version 1.0
*/
public class RabbitMQ {

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2017 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.commons.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @author joethei
* @version 1.0
*/
public class Files {
public static void unzip(File zipFile, File folder) {
byte[] buffer = new byte[1024];
try {
if (!folder.exists()) {
folder.mkdir();
}
ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String fileName = entry.getName();
File newFile = new File(folder + File.separator + fileName);
new File(newFile.getParent()).mkdirs();
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
}
zis.closeEntry();
zis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}

View File

@ -25,4 +25,6 @@ RabbitMQ.Host = vps.joethei.de
RabbitMQ.Port = 5672
RabbitMQ.Username = univento
RabbitMQ.Password = tYRHXZNm4exW@QB6rMm72pHnafrT8wQ5ebGPEetJDBVU2mj25kTVXuYeQavb#EYr
RabbitMQ.VirtualHost = univento
RabbitMQ.VirtualHost = univento
Gitlab.Host = https://gitlab.com/
Gitlab.token = add token here