BewareMyPower commented on code in PR #237:
URL: https://github.com/apache/pulsar-client-cpp/pull/237#discussion_r1172326880


##########
include/pulsar/c/consumer_configuration.h:
##########
@@ -98,6 +98,21 @@ typedef struct {
     long timeoutMs;
 } pulsar_consumer_batch_receive_policy_t;
 
+typedef struct {
+    // Name of the dead topic where the failing messages are sent.
+    // The default value is: sourceTopicName + "-" + subscriptionName + "-DLQ"
+    const char *dead_letter_topic;
+    // Maximum number of times that a message is redelivered before being sent 
to the dead letter queue.
+    // - The maxRedeliverCount must be greater than 0.
+    // - The default value is {INT_MAX} (DLQ is not enabled)
+    const int max_redeliver_count;
+    // Name of the initial subscription name of the dead letter topic.
+    // If this field is not set, the initial subscription for the dead letter 
topic is not created.
+    // If this field is set but the broker's `allowAutoSubscriptionCreation` 
is disabled, the DLQ producer
+    // fails to be created.
+    const char *initial_subscription_name;
+} pulsar_consumer_config_dead_letter_policy_t;

Review Comment:
   In addition, I think we'd better not to use raw struct. In C, the initial 
field values of a struct is not determined. For example,
   
   ```c
   #include <stdio.h>
   #include <stdlib.h>
   
   typedef struct {
     int x;
     const char *s;
   } A;
   
   int main(int argc, char *argv[]) {
     A a;
     printf("%d | %s\n", a.x, a.s);
     return 0;
   }
   ```
   
   ```bash
   $ gcc 0.c -O0
   $ ./a.out
   891409248 | (null)
   $ gcc 0.c -O2
   $ ./a.out
   0 | (null)
   ```
   
   Unlike C++ (from 11), a struct could not have initial values. 
   
   In addition, we'd better not to return a struct because its size could be 
greater than 8 bytes. POSIX APIs usually add a pointer argument as the output 
argument. Take [setrlimit/getrlimit](https://linux.die.net/man/2/setrlimit) for 
example:
   
   ```c
   int getrlimit(int resource, struct rlimit *rlim);
   int setrlimit(int resource, const struct rlimit *rlim);
   
   struct rlimit {
       rlim_t rlim_cur;  /* Soft limit */
       rlim_t rlim_max;  /* Hard limit (ceiling for rlim_cur) */
   };
   ```
   
   These problems exist for `pulsar_consumer_batch_receive_policy_t` as well. I 
will push a PR to fix it.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to