You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "graham-macdonald-simplisafe (via GitHub)" <gi...@apache.org> on 2026/04/21 21:10:56 UTC

[I] Expose isReplicated() / getReplicatedFrom() on the public Message API [pulsar-client-cpp]

graham-macdonald-simplisafe opened a new issue, #569:
URL: https://github.com/apache/pulsar-client-cpp/issues/569

   ## Feature Request
   
   Expose replication-origin metadata on the public `Message` class so consumer logic can detect whether a received message was produced locally or geo-replicated from a remote cluster.
   
   ### Requested API additions to `include/pulsar/Message.h`
   
   ```cpp
   /**
    * Check if this message was geo-replicated from another cluster.
    *
    * @return true if the message was replicated from a remote cluster,
    *         false if it was produced locally
    */
   bool isReplicated() const;
   
   /**
    * Get the name of the cluster this message was replicated from.
    *
    * @return the source cluster name, or an empty string if the message
    *         was produced locally (i.e. isReplicated() == false)
    */
   const std::string& getReplicatedFrom() const;
   ```
   
   ### Why this is straightforward to implement
   
   `MessageImpl` already holds `proto::MessageMetadata metadata` (see `lib/MessageImpl.h`), which contains the `replicated_from` optional string field from the Pulsar binary protocol. The implementation would simply wrap:
   
   ```cpp
   bool Message::isReplicated() const {
       return impl_->metadata.has_replicated_from() &&
              !impl_->metadata.replicated_from().empty();
   }
   
   const std::string& Message::getReplicatedFrom() const {
       return impl_->metadata.replicated_from();
   }
   ```
   
   The Java client already exposes both methods on `Message`. This brings the C++ client to parity.
   
   ### Use case: active-active geo-replication consumer routing
   
   In a geo-replicated active-active topology with a single replicated topic, consumers use `isReplicated()` as the routing signal for nack-based deferral:
   
   ```cpp
   if (!message.isReplicated()) {
       // Locally produced — process immediately
       process(message);
       consumer.acknowledge(message);
   } else if (message.getRedeliveryCount() == 0) {
       // Replicated from remote — defer; let the home-cluster consumer handle it.
       // If the home-cluster consumer is healthy, the replicated subscription cursor
       // sync will resolve this message before the delay expires.
       consumer.negativeAcknowledge(message);  // ~1s redelivery delay
   } else {
       // Home cluster is down — take over
       process(message);
       consumer.acknowledge(message);
   }
   ```
   
   Without `isReplicated()`, the only alternative is a dual-topic pattern (one topic per cluster), which doubles topic count and requires cluster-aware producer logic. Exposing `isReplicated()` enables a simpler single-topic topology.
   
   ### Related
   
   - The Node.js client (`pulsar-client-node`) wraps the C++ client and will be able to surface this once it is available here.
   - `replicateSubscriptionState` is also not yet surfaced in the Node.js client: apache/pulsar-client-node#478


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Expose isReplicated() / getReplicatedFrom() on the public Message API [pulsar-client-cpp]

Posted by "BewareMyPower (via GitHub)" <gi...@apache.org>.
BewareMyPower closed issue #569: Expose isReplicated() / getReplicatedFrom() on the public Message API
URL: https://github.com/apache/pulsar-client-cpp/issues/569


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org