Creating a Publisher

Create and connect to a publisher, then publish a message.

  1. Create and connect to a publisher:
    Publisher pub = project.createPublisher();
    pub.connect();
    
  2. To create and publish a message, call a stream and the stream name, call the message writer, call the row writer, and publish:
    String streamName = “Stream1”;
    Stream stream = project.getStream(streamName);
    MessageWriter mw = pub.getMessageWriter(streamName);
    RelativeRowWriter writer= mw.getRelativeRowWriter();
    mw.startEnvelope(0);  // can also  be mw.startTransaction() for transactions.
    for (int i = 0; i < recordsToPublish.length; i++) {
    	addRow(writer, incomingRecords[i], stream);
    }
    mw.endBlock();
    pub.publish(mw);