You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/08/12 09:26:02 UTC

[GitHub] [pulsar] alpreu opened a new pull request, #17075: [docs][java-client] Add sections for interceptor usage

alpreu opened a new pull request, #17075:
URL: https://github.com/apache/pulsar/pull/17075

   <!--
   ### Contribution Checklist
     
     - PR title format should be *[type][component] summary*. For details, see *[Guideline - Pulsar PR Naming Convention](https://docs.google.com/document/d/1d8Pw6ZbWk-_pCKdOmdvx9rnhPiyuxwq60_TrD68d7BA/edit#heading=h.trs9rsex3xom)*. 
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   
   ### Motivation
   
   The Pulsar documentation is missing information and usage examples about `ProducerInterceptor` and `ConsumerInterceptor`.
   
   ### Modifications
   
   Added sections for both interceptor types to the java-client documentation.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes / **no**)
     - The public API: (yes / **no**)
     - The schema: (yes / **no** / don't know)
     - The default values of configurations: (yes / **no**)
     - The wire protocol: (yes / **no**)
     - The rest endpoints: (yes / **no**)
     - The admin cli options: (yes / **no**)
     - Anything that affects deployment: (yes / **no** / don't know)
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ ] `doc-required` 
   (Your PR needs to update docs and you will update later)
     
   - [ ] `doc-not-needed` 
   (Please explain why)
     
   - [x] `doc` 
   (Your PR contains doc changes)
   
   - [ ] `doc-complete`
   (Docs have been already added)


-- 
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


[GitHub] [pulsar] Anonymitaet merged pull request #17075: [docs][java-client] Add sections for interceptor usage

Posted by GitBox <gi...@apache.org>.
Anonymitaet merged PR #17075:
URL: https://github.com/apache/pulsar/pull/17075


-- 
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


[GitHub] [pulsar] alpreu commented on pull request #17075: [docs][java-client] Add sections for interceptor usage

Posted by GitBox <gi...@apache.org>.
alpreu commented on PR #17075:
URL: https://github.com/apache/pulsar/pull/17075#issuecomment-1231736406

   I just updated the PR accordingly. The feature matrix will be updated as soon as my access request is accepted.
   
   Please find the screenshots of the changes below:
   <img width="1480" alt="Screenshot 2022-08-30 at 15 29 59" src="https://user-images.githubusercontent.com/11444089/187461171-e3b296d4-4025-43ba-b5c2-e01fcfcaffda.png">
   <img width="1536" alt="Screenshot 2022-08-30 at 15 30 17" src="https://user-images.githubusercontent.com/11444089/187461231-bd36f7ee-9107-4fc9-bd38-be0e4e676f88.png">
   <img width="1508" alt="Screenshot 2022-08-30 at 15 30 27" src="https://user-images.githubusercontent.com/11444089/187461244-cc9f4663-f687-4d23-aa71-2187e27b98cb.png">
   


-- 
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


[GitHub] [pulsar] Anonymitaet commented on a diff in pull request #17075: [docs][java-client] Add sections for interceptor usage

Posted by GitBox <gi...@apache.org>.
Anonymitaet commented on code in PR #17075:
URL: https://github.com/apache/pulsar/pull/17075#discussion_r945557867


##########
site2/docs/client-libraries-java.md:
##########
@@ -652,6 +652,43 @@ Producer<byte[]> producer = client.newProducer()
 By default, producer chunks the large message based on max message size (`maxMessageSize`) configured at broker (eg: 5MB). However, client can also configure max chunked size using producer configuration `chunkMaxMessageSize`.
 > **Note:** To enable chunking, you need to disable batching (`enableBatching`=`false`) concurrently.
 
+### Intercept messages
+
+`ProducerInterceptor`s intercept and possibly mutate messages received by the producer before they are published to the brokers.
+
+The interface has three main events:
+* `eligible` checks if the interceptor can be applied to the message.
+* `beforeSend` is triggered before the producer sends the message to the broker. You can modify messages within this event.
+* `onSendAcknowledgement` is triggered when the message is acknowledged by the broker or the sending failed.
+
+To intercept messages, you can add one or multiple `ProducerInterceptor`s when creating a `Producer` as follows.
+
+```java
+
+Producer<byte[]> producer = client.newProducer()
+        .topic(topic)
+        .intercept(new ProducerInterceptor {
+			@Override
+			boolean eligible(Message message) {
+			    return true;  // process all messages
+			}
+
+			@Override
+			Message beforeSend(Producer producer, Message message) {
+			    // user-defined processing logic
+			}
+
+			@Override
+			void onSendAcknowledgement(Producer producer, Message message, MessageId msgId, Throwable exception) {
+			    // user-defined processing logic
+			}
+        })
+        .create();
+
+```
+
+> **Note:** If you are using multiple interceptors, they apply in the order they are passed to the `intercept` method.

Review Comment:
   ```suggestion
   :::note
   
   If you are using multiple interceptors, they apply in the order they are passed to the `intercept` method.
   
   :::
   ```
   
   Please follow the syntax here: https://docs.google.com/document/d/12De2btkDHQVaqUlHjTqERmroMLKGhHdiC7rEttFTyqc/edit#bookmark=id.jis8plesauvo



-- 
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