Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improve][doc]Add introduction of transaction isolation level in the txn-advanced-features.md #712

Merged
merged 15 commits into from
Feb 29, 2024
Merged
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion docs/txn-advanced-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,34 @@ If you want to enable authentication with transactions, follow the steps below.

2. [Configure authentication](security-overview/#authentication) in a Pulsar client.

## Select transaction isolation level

To enhance the flexibility of Pulsar transactions, they support two distinct isolation levels:
- `READ_COMMITTED`(default): The consumer can only consume all transactional messages that have been committed.
- `READ_UNCOMMITTED`: The consumer can consume all messages, even transactional messages that have been aborted.

For different scenarios, they use different subscriptions and choose different isolation levels. One needs transaction, one does not. In general, multiple subscriptions of the same topic do not all
require transaction guarantees. Some want low latency without the exact-once semantic guarantee (like a real-time monitoring system), and some must require the exactly-once guarantee (e.g., business processing systems).
visortelle marked this conversation as resolved.
Show resolved Hide resolved
Users can freely choose different isolation levels according to different scenarios.

Note that this is a subscription dimension configuration, and all consumers under the same subscription need to be configured with the same IsolationLevel.
visortelle marked this conversation as resolved.
Show resolved Hide resolved
visortelle marked this conversation as resolved.
Show resolved Hide resolved

This example selects `READ_UNCOMMITTED` Isolation level in the consumer builder:
visortelle marked this conversation as resolved.
Show resolved Hide resolved

```java
Consumer<String> consumer = client
.newConsumer(Schema.STRING)
.topic("persistent://my-tenant/my-namespace/my-topic")
.subscriptionName("my-subscription")
.subscriptionType(SubscriptionType.Shared)
.subscriptionIsolationLevel(SubscriptionIsolationLevel.READ_COMMITTED) // Adding the isolation level configuration
visortelle marked this conversation as resolved.
Show resolved Hide resolved
.subscribe();
```

## Guarantee exactly-once semantics

If you want to guarantee exactly-once semantics with transactions, you can [enable message deduplication at the broker, namespace, or topic level](cookbooks-deduplication.md#enable-message-deduplication-at-namespace-or-topic-level).

## Related topics

- To get up quickly, see [Pulsar transactions - Get started](txn-use.md).
- To get up quickly, see [Pulsar transactions - Get started](txn-use.md).
Loading