in simulator/src/main/java/com/google/cloud/PubSubConsumer.java [87:113]
private static void publish(Publisher publisher, PubsubMessage message, Stats stats) {
// Capture stats and publish
final long messageSize = message.getSerializedSize();
final long pubTime = System.nanoTime();
ApiFuture<String> future = publisher.publish(message);
ApiFutures.addCallback(future, new ApiFutureCallback<>() {
@Override
public void onFailure(Throwable throwable) {
if (throwable instanceof ApiException) {
ApiException apiException = ((ApiException) throwable);
// details on the API exception
System.out.println("Code: " + apiException.getStatusCode().getCode());
System.out.println("isRetryable: " + apiException.isRetryable());
}
System.out.println("Error publishing message: " + throwable.getMessage());
}
// Track stats on confirmed publish
@Override
public void onSuccess(String messageId) {
stats.add(System.nanoTime() - pubTime, 1, messageSize);
}
}, MoreExecutors.directExecutor());
}