Search in sources :

Example 11 with FCPublisher

use of org.nustaq.fastcast.api.FCPublisher 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);
    }
}
Also used : FCPublisher(org.nustaq.fastcast.api.FCPublisher) ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) RateMeasure(org.nustaq.fastcast.util.RateMeasure) PublisherConf(org.nustaq.fastcast.config.PublisherConf)

Aggregations

FCPublisher (org.nustaq.fastcast.api.FCPublisher)11 FCSubscriber (org.nustaq.fastcast.api.FCSubscriber)5 ObjectPublisher (org.nustaq.fastcast.api.util.ObjectPublisher)5 FastCast (org.nustaq.fastcast.api.FastCast)4 RateMeasure (org.nustaq.fastcast.util.RateMeasure)4 FSTStructAllocator (org.nustaq.offheap.structs.FSTStructAllocator)4 Executor (java.util.concurrent.Executor)3 ObjectSubscriber (org.nustaq.fastcast.api.util.ObjectSubscriber)3 PublisherConf (org.nustaq.fastcast.config.PublisherConf)3 Bytez (org.nustaq.offheap.bytez.Bytez)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 Histogram (org.HdrHistogram.Histogram)2 Sleeper (org.nustaq.fastcast.util.Sleeper)2 File (java.io.File)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FSTStruct (org.nustaq.offheap.structs.FSTStruct)1