Heimdall is supposed to be a lightweight and easy to use pub sub communication framework you can build your infrastructure on.
- Install Maven
- Clone this repo
- Install:
mvn clean install
Maven dependencies
Client:
<dependency>
<groupId>de.d3adspace</groupId>
<artifactId>heimdall-client</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Server:
<dependency>
<groupId>de.d3adspace</groupId>
<artifactId>heimdall-server</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Commons:
<dependency>
<groupId>de.d3adspace</groupId>
<artifactId>heimdall-commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Server:
package de.d3adspace.heimdall.client;
import de.d3adspace.heimdall.server.HeimdallServer;
import de.d3adspace.heimdall.server.HeimdallServerFactory;
import de.d3adspace.heimdall.server.config.HeimdallServerConfig;
import de.d3adspace.heimdall.server.config.HeimdallServerConfigBuilder;
public class HeimdallServerExample {
public static void main(String[] args) {
HeimdallServerConfig config = new HeimdallServerConfigBuilder()
.setServerHost("localhost")
.setServerPort(1337)
.createHeimdallServerConfig();
HeimdallServer heimdallServer = HeimdallServerFactory.createHeimdallServer(config);
heimdallServer.start();
}
}
Client:
package de.d3adspace.heimdall.client;
import de.d3adspace.heimdall.client.HeimdallClient;
import de.d3adspace.heimdall.client.HeimdallClientFactory;
import de.d3adspace.heimdall.client.annotation.Channel;
import de.d3adspace.heimdall.client.config.HeimdallClientConfig;
import de.d3adspace.heimdall.client.config.HeimdallClientConfigBuilder;
import de.d3adspace.heimdall.client.handler.PacketHandler;
import org.json.JSONObject;
public class HeimdallClientExample {
public static void main(String[] args) {
HeimdallClientConfig config = new HeimdallClientConfigBuilder()
.setServerHost("localhost")
.setServerPort(1337)
.createHeimdallClientConfig();
HeimdallClient client = HeimdallClientFactory.createHeimdallClient(config);
client.connect();
PacketHandler packetHandler = new PacketHandlerExample();
client.subscribe(packetHandler);
client.publish("cluster", new JSONObject().put("Hello", "World!"));
client.unsubscribe(packetHandler);
client.disconnect();
}
}
package de.d3adspace.heimdall.client;
import de.d3adspace.heimdall.client.annotation.Channel;
import de.d3adspace.heimdall.client.handler.PacketHandler;
import org.json.JSONObject;
@Channel("cluster")
public class PacketHandlerExample implements PacketHandler {
public void handlePacket(JSONObject jsonObject) {
System.out.println("Message in cluster: " + jsonObject);
}
}