Skip to content

Commit

Permalink
Add producer access mode examples for Java and C++ client. (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibd authored Apr 25, 2023
1 parent e819fc1 commit c0a708a
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion docs/client-libraries-producers.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,51 @@ This example shows how to set the `EnforceUnencrypted` encryption policy.
</TabItem>
</Tabs>
````
````

## Configure access mode

[Access mode](concepts-clients.md#access-mode) allows applications to require exclusive producer access on a topic to achieve a "single-writer" situation.

This example shows how to set producer access mode.

````mdx-code-block
<Tabs groupId="lang-choice"
defaultValue="Java"
values={[{"label":"Java","value":"Java"},{"label":"C++","value":"C++"}]}>
<TabItem value="Java">
::: note
This feature is supported in Java client 2.8.0 or later versions.
:::
```java
Producer<byte[]> producer = client.newProducer()
.topic(topic)
.accessMode(ProducerAccessMode.Exclusive)
.create();
```
</TabItem>
<TabItem value="C++">
::: note
This feature is supported in C++ client 3.1.0 or later versions.
:::
```cpp
Producer producer;
ProducerConfiguration producerConfiguration;
producerConfiguration.setAccessMode(ProducerConfiguration::Exclusive);
client.createProducer(topicName, producerConfiguration, producer);
```
</TabItem>
</Tabs>
````

0 comments on commit c0a708a

Please sign in to comment.