Created
April 9, 2022 04:15
-
-
Save bijukunjummen/5e89e4319bc51f36ff08488572e07f37 to your computer and use it in GitHub Desktop.
Publish a message to GCP Pub/Sub Topic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Mono<Void> publish(Message message) { | |
ByteString data = ByteString.copyFromUtf8(JsonUtils.writeValueAsString(message, objectMapper)); | |
PubsubMessage pubSubMessage = PubsubMessage.newBuilder().setData(data).build(); | |
ApiFuture<String> messageIdFuture = publisher.publish(pubSubMessage); | |
Mono<String> messageIdMono = ApiFutureUtil.toMono(messageIdFuture); | |
return messageIdMono.then(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment