You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Order savedOrder = orderRepository.save(newOrder); // ✅ Returns saved document
3727
3727
```
3728
3728
3729
+
**⚠️ Reactor / reactive streams — never set `contentResponseOnWriteEnabled(false)` on `CosmosAsyncClient`:**
3730
+
3731
+
When using `CosmosAsyncClient` with Project Reactor, setting `contentResponseOnWriteEnabled(false)` causes `CosmosItemResponse.getItem()` to return `null`. Reactor does not allow `null` signals in its pipeline (Reactive Streams Specification, Rule 2.13), so any downstream `.map(CosmosItemResponse::getItem)` or similar operator throws a `NullPointerException` from inside Reactor internals — not from your code — making the root cause very hard to diagnose.
3732
+
3733
+
```java
3734
+
// ❌ Causes NPE in reactive stream — never do this with CosmosAsyncClient
.map(CosmosItemResponse::getItem) // ✅ Non-null, safe in Reactor
3756
+
.block();
3757
+
```
3758
+
3759
+
```java
3760
+
// ✅ Option 2: If you must suppress content, guard against null before mapping
3761
+
container.upsertItem(item)
3762
+
.flatMap(response -> {
3763
+
MyItem result = response.getItem();
3764
+
return result !=null?Mono.just(result) :Mono.empty();
3765
+
});
3766
+
```
3767
+
3729
3768
**When NOT to enable content response:**
3730
3769
3731
-
If you don't need the created document (fire-and-forget writes), leave it disabled to save bandwidth:
3770
+
If you don't need the created document (fire-and-forget writes)**and you are using the synchronous `CosmosClient`**, leave it disabled to save bandwidth:
3732
3771
3733
3772
```java
3734
-
// High-throughput ingestion - don't need response content
3773
+
// High-throughput ingestion with synchronous client - don't need response content
@@ -3751,7 +3790,8 @@ Enabling content response does NOT increase RU cost - the document is already fe
3751
3790
- Java SDK returns null from `getItem()` by default for created/upserted items — enable `contentResponseOnWriteEnabled(true)` to get documents back after writes
3752
3791
- Can be set at client level (all operations) or per-request
3753
3792
- Spring Data Cosmos handles both unwrapping and content response automatically
3754
-
- Disable content response for high-throughput scenarios where response content is not needed
3793
+
-**Never set `contentResponseOnWriteEnabled(false)` with `CosmosAsyncClient` / reactive streams** — it causes `NullPointerException` in the Reactor pipeline
3794
+
- Only disable content response for high-throughput fire-and-forget writes with the synchronous `CosmosClient`
3755
3795
3756
3796
Reference: [Azure Cosmos DB Java SDK best practices](https://learn.microsoft.com/azure/cosmos-db/nosql/best-practice-java)
Order savedOrder = orderRepository.save(newOrder); // ✅ Returns saved document
139
139
```
140
140
141
+
**⚠️ Reactor / reactive streams — never set `contentResponseOnWriteEnabled(false)` on `CosmosAsyncClient`:**
142
+
143
+
When using `CosmosAsyncClient` with Project Reactor, setting `contentResponseOnWriteEnabled(false)` causes `CosmosItemResponse.getItem()` to return `null`. Reactor does not allow `null` signals in its pipeline (Reactive Streams Specification, Rule 2.13), so any downstream `.map(CosmosItemResponse::getItem)` or similar operator throws a `NullPointerException` from inside Reactor internals — not from your code — making the root cause very hard to diagnose.
144
+
145
+
```java
146
+
// ❌ Causes NPE in reactive stream — never do this with CosmosAsyncClient
.map(CosmosItemResponse::getItem) // ✅ Non-null, safe in Reactor
168
+
.block();
169
+
```
170
+
171
+
```java
172
+
// ✅ Option 2: If you must suppress content, guard against null before mapping
173
+
container.upsertItem(item)
174
+
.flatMap(response -> {
175
+
MyItem result = response.getItem();
176
+
return result !=null?Mono.just(result) :Mono.empty();
177
+
});
178
+
```
179
+
141
180
**When NOT to enable content response:**
142
181
143
-
If you don't need the created document (fire-and-forget writes), leave it disabled to save bandwidth:
182
+
If you don't need the created document (fire-and-forget writes)**and you are using the synchronous `CosmosClient`**, leave it disabled to save bandwidth:
144
183
145
184
```java
146
-
// High-throughput ingestion - don't need response content
185
+
// High-throughput ingestion with synchronous client - don't need response content
@@ -163,6 +202,7 @@ Enabling content response does NOT increase RU cost - the document is already fe
163
202
- Java SDK returns null from `getItem()` by default for created/upserted items — enable `contentResponseOnWriteEnabled(true)` to get documents back after writes
164
203
- Can be set at client level (all operations) or per-request
165
204
- Spring Data Cosmos handles both unwrapping and content response automatically
166
-
- Disable content response for high-throughput scenarios where response content is not needed
205
+
-**Never set `contentResponseOnWriteEnabled(false)` with `CosmosAsyncClient` / reactive streams** — it causes `NullPointerException` in the Reactor pipeline
206
+
- Only disable content response for high-throughput fire-and-forget writes with the synchronous `CosmosClient`
167
207
168
208
Reference: [Azure Cosmos DB Java SDK best practices](https://learn.microsoft.com/azure/cosmos-db/nosql/best-practice-java)
0 commit comments