Skip to content

Instantly share code, notes, and snippets.

@bijukunjummen
Created April 9, 2022 04:31
Show Gist options
  • Select an option

  • Save bijukunjummen/ff89e793cab7669c1abe0b6895dbf757 to your computer and use it in GitHub Desktop.

Select an option

Save bijukunjummen/ff89e793cab7669c1abe0b6895dbf757 to your computer and use it in GitHub Desktop.
Publish to Cloud Pub/Sub using Spring Cloud GCP
public Mono<Void> publish(Message message) {
ByteString data = ByteString.copyFromUtf8(JsonUtils.writeValueAsString(message, objectMapper));
PubsubMessage pubSubMessage = PubsubMessage.newBuilder().setData(data).build();
return Mono.fromFuture(pubSubTemplate.publish(pubSubProperties.topic(), pubSubMessage).completable()).then();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment