Java and Scala implementation of Event Fabric API to send events.
To build the project use Maven 2
you will need a recent version installed, then do:
//If you are using Eclipse IDE, just call:
mvn eclipse:eclipse
// to compile
mvn compile
// to test
mvn test
// to create a jar
mvn package
//Now you'll want to install the artifact you've generated (the JAR file) in your local repository (~/.m2/repository is the default location)
mvn install
Watch this video to understand how to connect your Java Application to Event Fabric. In this video we use examples/salesapp to explain step by step how to do it.
see examples folder for more examples.
using java:
import com.eventfabric.api.client.EventClient;
import com.eventfabric.model.Event;
YourEntity yourEntity = new YourEntity();
EventClient eventClient = new EventClient(this.efUsername, this.efPassword);
try {
boolean authenticated = eventClient.authenticate();
if (authenticated) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode value = (ObjectNode) mapper.valueToTree(yourEntity);
Event event = new Event("my.channel", value);
Response response = eventClient.send(event);
if (response.getStatus() == 201) {
System.out.println("Sale sent to Event Fabric");
} else {
System.out.println("Error sending Sale to Event Fabric");
}
}
} catch (IOException e) {
e.printStackTrace();
}
pom.xml:
<dependency>
<groupId>com.eventfabric</groupId>
<artifactId>api</artifactId>
<version>0.1.0</version>
</dependency>
using scala:
import com.eventfabric.api.client.EventClient
import com.eventfabric.model.Event
// create client
val client = new EventClient("admin", "notadmin")
// authenticate
val success = client.authenticate()
println("successful? " + success)
// create the event value to send
val value = new java.util.LinkedHashMap[String, Object]()
value.put("count", 4:java.lang.Integer)
value.put("price", 12.3:java.lang.Double)
value.put("yes", true:java.lang.Boolean)
// create the event to send
val event = new Event("my.channel", value)
// send the event
val response = client.send(event)
// do something with the response
println(response.getStatus)
println(response.getResult)
if your endpoint is not the default one you have to create a custom event client pointing to your API instance:
import com.eventfabric.api.client.{EventClient, EndPointInfo}
val eventEndpoint = new EndPointInfo("localhost", "/ef/api/event", 8080, false)
val sessionEndpoint = new EndPointInfo("localhost", "/ef/api/session", 8080, false)
// create client
val client = new EventClient("admin", "notadmin", eventEndpoint, sessionEndpoint)
MIT