https://github.com/jesty/shedlock-provider-cosmosdb
A custom provider to use ShedLock with CosmosDB
https://github.com/jesty/shedlock-provider-cosmosdb
Last synced: about 2 months ago
JSON representation
A custom provider to use ShedLock with CosmosDB
- Host: GitHub
- URL: https://github.com/jesty/shedlock-provider-cosmosdb
- Owner: jesty
- License: apache-2.0
- Created: 2019-10-21T09:43:11.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T08:05:27.000Z (over 5 years ago)
- Last Synced: 2025-03-25T13:02:22.891Z (2 months ago)
- Language: Java
- Size: 19.5 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ShedLock Provider for CosmosDB
[ShedLock](https://github.com/lukas-krecan/ShedLock) is a Java library that can be used to be sure that a scheduled task runs only once at the same time in a distributed environment.
The lock may be implemented using various providers like Redis, MongoDB, Hazelcast and so on.
Using the provider in this project, you can rely on Cosmos DB.
To use it, you just need to:
- import the dependency in your pom.xml:
```xmlnet.javacrumbs.shedlock
shedlock-core
3.0.0com.github.jesty
shedlock-provider-cosmosdb
1.0.0```
- instantiate the right provider, e.g. using Spring with annotation-based configuration:
```java
import com.github.jesty.shedlock.provider.cosmosdb.CosmosDBLockProvider;...
@Bean
public LockProvider lockProvider(CosmosContainer container) {
return new CosmosDBLockProvider(container, "lockGroup"); //lockGroup is the partition key
}
```For more information about ShedLock refer to the [original documentation](https://github.com/lukas-krecan/ShedLock).
The lock relies on a Cosmos DB's collection. In order to perform the lock you have to create a stored procedure ([checkLockAndAcquire.js](https://github.com/jesty/ShedLock/tree/master/providers/cosmosdb/shedlock-provider-cosmosdb/storedprocedures/checkLockAndAcquire.js)) in your Cosmos DB instance.
## Build from source
Before building this project you need to checkout ShedLock and install _shedlock-test-support_ in your local Maven repository:
> git clone https://github.com/lukas-krecan/ShedLock.git
> cd shedlock-test-support
> mvn clean installFinally, you can build this project by running:
> mvn package
There is an [integration test](https://github.com/jesty/ShedLock/tree/master/providers/cosmosdb/shedlock-provider-cosmosdb/src/test/java/net/javacrumbs/shedlock/provider/cosmosdb/CosmosDbProviderIntegrationTest.java) that can be run using:
> mvn verify
This test need a Cosmos DB instance on Azure, or a [Cosmos DB local emulator](https://docs.microsoft.com/azure/cosmos-db/local-emulator) instance running.
The instance parameters must be set in [config.properties](https://github.com/jesty/ShedLock/tree/master/providers/cosmosdb/shedlock-provider-cosmosdb/src/test/resources/config.properties).If you would like to build or install the project in your local repository without running integration tests, you can run:
> mvn install -DskipITs