Forest Bus Java Client Library
This is a Java client library for Forest Bus. It requires the following JARs to be on the classpath:
The Forest Bus client library Java Doc is included in the source distribution as well as on this site.
The client is distributed as both a JAR and as source code.
Compatible with Forest Bus server 1.0.
/*
This code assumes a three node cluster is running on localhost, configured as follows:
# forest-bus-server -id testcluster -cbor :5000 -name :3000 -path ~/forest-data/bus1
# forest-bus-server -id testcluster -cbor :5001 -name :3001 -path ~/forest-data/bus2
# forest-bus-server -id testcluster -cbor :5002 -name :3002 -path ~/forest-data/bus3
On first start the servers need configuring with their peers:
# forest-admin -id testcluster peers :3000,:3001,:3002
A test topic also needs to have been created:
# forest-admin -id testcluster topic test
*/
import com.owlfish.forestbus.*;
import java.util.Arrays;
public class TestShort {
public static void main (String[] args) {
try {
String[] nodes = {"localhost:5000", "localhost:5001", "localhost:5002"};
ForestClient fc = new ForestClient ("testcluster", nodes);
byte[] msgToSend = "A test from Java!".getBytes();
byte[][] msgBatch = new byte[1][];
msgBatch [0] = msgToSend;
long ids[] = fc.sendMessages ("test", msgBatch, true);
System.out.println ("Created message " + Long.toString (ids[0]));
GetMessagesResult messages = fc.getMessages("test", 1, 1, true);
for (byte[] msg : messages.receivedMessages) {
System.out.println ("Message retrieved: " + Arrays.toString(msg));
}
fc.close();
}
catch (Exception e) {
System.out.println("Exception during forest bus client call: " + e.toString());
e.printStackTrace();
}
}
}
The full list of my published Software
Made with PubTal 3.5
Copyright 2021 Colin StewartEmail: colin at owlfish.com