cosmos db error while createContainerIfNotExists

Claudio Resende 221 Reputation points
2021-06-25T13:27:02.247+00:00

I am using azure cosmos db and all of the sudden, it stopped working with the error bellow

Method called:

   cosmosDatabase.createContainerIfNotExists(containerProperties);  




   java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-10  
   at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.5.jar:3.4.5]  
   at reactor.core.publisher.Mono.block(Mono.java:1703) ~[reactor-core-3.4.5.jar:3.4.5]  
   at com.azure.cosmos.CosmosDatabase.blockContainerResponse(CosmosDatabase.java:288) ~[azure-cosmos-4.14.0.jar:na]  
   at com.azure.cosmos.CosmosDatabase.createContainerIfNotExists(CosmosDatabase.java:195) ~[azure-cosmos-4.14.0.jar:na]  

method called save()

   java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread parallel-12  
   at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:83) ~[reactor-core-3.4.5.jar:3.4.5]  
   at reactor.core.publisher.Mono.block(Mono.java:1703) ~[reactor-core-3.4.5.jar:3.4.5]  
   at com.azure.cosmos.CosmosContainer.blockItemResponse(CosmosContainer.java:235) ~[azure-cosmos-4.14.0.jar:na]  
   at com.azure.cosmos.CosmosContainer.createItem(CosmosContainer.java:156) ~[azure-cosmos-4.14.0.jar:na]  
   at service.save(CosmosRepositoryImpl.java:33) ~[classes/:  

notice that I am not using Async database.

A bit more of context:

it is is being processed inside a stream where I get a Flux object and iterate over it, and the

   <dependency>  
               <groupId>com.azure.spring</groupId>  
               <artifactId>azure-spring-boot-starter-cosmos</artifactId>  
               <version>3.4.0</version>  
           </dependency>  

A react controller call the bellow methods. P.S notice that I changed the names business-related.

   `  
   Service class:  
        
       public Mono<ResponseObect> myMethod(final RequestObject request) {  
           return getSomeFlux(request).flatMap(someObject -> {  
                      RepositoryClass.save(someObject);  
                       return Flux.just(someObject);  
                   }  
           ).count().map(ResponseObect::new);  
     
       }  
     
   Repo Class:  
     
       public void save(final MyObject newItem, final String containerName) {  
           CosmosContainer container = getContainer(containerName);  
           CosmosItemResponse<MyObject> savedItem = container.createItem(newItem);  
     
           if (savedItem.getStatusCode() != 201) {  
                       do logging  
           }  
       }  
     
       private CosmosContainer getContainer(final String containerName) {  
           CosmosUtils.createContainerIfNotExists(containerName, cosmosDatabase);  
           return cosmosDatabase.getContainer(containerName);  
       }  
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,442 questions
{count} votes