@@ -216,15 +216,12 @@ public String getTopicNameString() {
216216 * @return the message ID wrapped in a future.
217217 */
218218 public ApiFuture <String > publish (PubsubMessage message ) {
219- if (shutdown .get ()) {
220- throw new IllegalStateException ("Cannot publish on a shut-down publisher." );
221- }
219+ Preconditions .checkState (!shutdown .get (), "Cannot publish on a shut-down publisher." );
222220
223221 final String orderingKey = message .getOrderingKey ();
224- if (orderingKey != null && !orderingKey .isEmpty () && !enableMessageOrdering ) {
225- throw new IllegalStateException (
226- "Cannot publish a message with an ordering key when message ordering is not enabled." );
227- }
222+ Preconditions .checkState (
223+ orderingKey != null && !orderingKey .isEmpty () && !enableMessageOrdering ,
224+ "Cannot publish a message with an ordering key when message ordering is not enabled." );
228225
229226 final OutstandingPublish outstandingPublish =
230227 new OutstandingPublish (messageTransform .apply (message ));
@@ -361,9 +358,13 @@ private void publishOutstandingBatch(final OutstandingBatch outstandingBatch) {
361358 public void onSuccess (PublishResponse result ) {
362359 try {
363360 if (result .getMessageIdsCount () != outstandingBatch .size ()) {
364- Throwable t = new IllegalStateException (String .format (
365- "The publish result count %s does not match " + "the expected %s results. Please contact Cloud Pub/Sub support "
366- + "if this frequently occurs" , result .getMessageIdsCount (), outstandingBatch .size ()));
361+ Throwable t =
362+ new IllegalStateException (
363+ String .format (
364+ "The publish result count %s does not match "
365+ + "the expected %s results. Please contact Cloud Pub/Sub support "
366+ + "if this frequently occurs" ,
367+ result .getMessageIdsCount (), outstandingBatch .size ()));
367368 for (OutstandingPublish oustandingMessage : outstandingBatch .outstandingPublishes ) {
368369 oustandingMessage .publishResult .setException (t );
369370 }
0 commit comments