examples/pubsub-publish-avro-example/src/main/java/com/google/cloud/pso/pubsub/common/ObjectPublisher.java
/**
     * Publishes the record asynchronously and adds a listener for the {@link ApiFuture}
     * that is returned.
     *
     * @param record The record to be published.
     * @throws IOException
     */
Publishes the record asynchronously and adds a listener for the  ApiFuture
that is returned.

@param record The record to be published.
Publishes the record asynchronously and adds a listener for the ApiFuture that is returned . @param record The record to be published .
private void publish(T record) throws IOException {
        awaitedFutures.incrementAndGet();
        ByteString byteString = serialize(record);
        PubsubMessage message = PubsubMessage.newBuilder().setData(byteString).build();
        ApiFuture<String> response = publisher.publish(message);
        response.addListener(
                () -> {
                    try {
                        response.get();
                    } catch (Exception e) {
                        System.out.println("Could not publish a message: " + e);
                    } finally {
                        awaitedFutures.decrementAndGet();
                    }
                },
                executor);
    }
private void publish ( T record ) throws IOException { awaitedFutures . incrementAndGet ( ) ; ByteString byteString = serialize ( record ) ; PubsubMessage message = PubsubMessage . newBuilder ( ) . setData ( byteString ) . build ( ) ; ApiFuture < String > response = publisher . publish ( message ) ; response . addListener ( ( ) -> { try { response . get ( ) ; } catch ( Exception e ) { System . out . println ( "Could not publish a message: " + e ) ; } finally { awaitedFutures . decrementAndGet ( ) ; } } , executor ) ; }
Publishes the record asynchronously and adds a listener for the {@link ApiFuture}
 that is returned.
Publishes the record asynchronously and adds a listener for the { @link ApiFuture } that is returned .