Nirvana Java - Event Fragmentation on Nirvana Channels
By default, Nirvana will only allow events to be published if the size of the event is less than 1Mb. Although this limit can be changed in the Enterprise Manager (see Config tab, FanoutValues/MaxBufferSize), this is not generally recommended; it is usually far more efficient to fragment large events into smaller chunks for publishing.
Nirvana can transparently fragment and reconstruct events. Thus, a developer need only invoke one method call to fragment and publish an event. In the same way, the resulting event will be transparently reconstructed when received by the consumer. Under the hood, however, Nirvana will publish several smaller messages representing the large event.
A summary of the code needed to publish and consume fragmented events is provided below.
The code to publish a large event using fragmentation is as follows:
// The chunk_size is the max size (bytes) for each event. Multiple events will // be published of size chunk_size until the entire event has been sent. int chunk_size = 50000; fw = new nConsumeEventFragmentWriter(myChannel,chunk_size); // Rather than myChannel.publish(evt), we let the fragment writer handle the publish fw.publish(evt)
The code to consume a large event using fragmentation is as follows:
// In this example the enclosing class implements nEventListener fr = new nConsumeEventFragmentReader(this); // Rather than directly add 'this' as the nEventListener, add the new fragment reader myChannel.addSubscriber(fr);