use of org.nustaq.fastcast.config.PublisherConf in project fast-cast by RuedigerMoeller.
the class MPPublisher method main.
public static void main(String[] arg) {
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("MPUB");
configureFastCast();
FCPublisher pub = FastCast.getFastCast().onTransport("default").publish(// unique-per-transport topic id
new PublisherConf(1).numPacketHistory(// how many packets are kept for retransmission requests
33_000).pps(// packets per second rate limit.
10_000));
MultipleProtocol.initStructFactory();
FSTStructAllocator onHeapAlloc = new FSTStructAllocator(10_000);
AMessage aMsg = onHeapAlloc.newStruct(new AMessage());
OtherMessage other = onHeapAlloc.newStruct(new OtherMessage());
ComposedMessage composed = onHeapAlloc.newStruct(new ComposedMessage());
ThreadLocalRandom random = ThreadLocalRandom.current();
// could directly send raw on publisher
RateMeasure measure = new RateMeasure("msg/s");
int count = 0;
FSTStruct msg = null;
while (true) {
measure.count();
// fill in data
switch(random.nextInt(3)) {
case 0:
for (int i = 0; i < aMsg.stringArrayLen(); i++) {
aMsg.stringArray(i).setString("Hello " + i);
}
aMsg.setL(count++);
msg = aMsg;
break;
case 1:
other.setQuantity(count++);
other.setValue(random.nextDouble());
msg = other;
break;
case 2:
aMsg.stringArray(0).setString("Hello !");
aMsg.stringArray(1).setString("Hello !!");
aMsg.setL(count++);
other.setQuantity(count++);
other.setValue(random.nextDouble());
// does a copy !
composed.setMegA(aMsg);
// does a copy !
composed.setMsgB(other);
msg = composed;
break;
}
// send message
while (!pub.offer(null, msg.getBase(), msg.getOffset(), msg.getByteSize(), false)) {
/* spin */
}
}
}
use of org.nustaq.fastcast.config.PublisherConf in project fast-cast by RuedigerMoeller.
the class StructPublisher method main.
public static void main(String[] arg) {
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("PUB");
configureFastCast();
FCPublisher pub = FastCast.getFastCast().onTransport("default").publish(// unique-per-transport topic id
new PublisherConf(1).numPacketHistory(// how many packets are kept for retransmission requests
33_000).pps(// packets per second rate limit.
10_000));
Protocol.initStructFactory();
Protocol.PriceUpdateStruct template = new Protocol.PriceUpdateStruct();
FSTStructAllocator onHeapAlloc = new FSTStructAllocator(0);
// speed up instantiation
Protocol.PriceUpdateStruct msg = onHeapAlloc.newStruct(template);
ThreadLocalRandom current = ThreadLocalRandom.current();
// could directly send raw on publisher
RateMeasure measure = new RateMeasure("msg/s");
while (true) {
measure.count();
// fill in data
Protocol.InstrumentStruct instrument = msg.getInstrument();
instrument.getMnemonic().setString("BMW");
instrument.setInstrumentId(13);
msg.setPrc(99.0 + current.nextDouble(10.0) - 5);
msg.setQty(100 + current.nextInt(10));
// send message
while (!pub.offer(null, msg.getBase(), msg.getOffset(), msg.getByteSize(), false)) {
/* spin */
}
}
}
use of org.nustaq.fastcast.config.PublisherConf in project fast-cast by RuedigerMoeller.
the class ProgrammaticConfiguredPublisher method main.
public static void main(String[] arg) {
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("PUB");
configureFastCast();
FCPublisher pub = FastCast.getFastCast().onTransport("default").publish(// unique-per-transport topic id
new PublisherConf(1).numPacketHistory(// how long packets are kept for retransmission requests
40_000).pps(// packets per second rate limit. So max traffic for topic = 5000*2500 = 12.5 MB/second
5000));
// could directly send raw on publisher
// while( ! pub.offer(..) ) { /* spin */ }
// or use a helper for fast-serialized messages
ObjectPublisher opub = new ObjectPublisher(pub);
RateMeasure measure = new RateMeasure("msg/s");
while (true) {
measure.count();
opub.sendObject(// all listeners should receive (by specifying a nodeId, a specific subscriber can be targeted)
null, // serializable object
"Hello " + System.currentTimeMillis(), // allow for 'batching' several messages into one (will create slight latency)
false);
}
}
Aggregations