Template / Example for a microservice using spring cache abstraction and EHCACHE library.
Spring Cache Abstraction: https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/cache.html
EHCACHE: https://www.ehcache.org/
For device / asset integration the external id (unique external identifier) is used for correlate devices and assets. To keep the communication less frequent to the platform a managed cache can be used. Be aware server side (microserivce) integration has fewer problems with frequent platform communication. This approach is more interesting for agent and edge development, where bandwidth to cloud isn't always high.
This example shows how external IDs (Identity) and managed objects (Inventory) get cached using ehcache. Also a inventory listener is implemented. If the microservice gets notified that managed object has changed, managed object will be removed (evict) from cache. There are also many configuration possibilities for ehcache, see ehcache.xml. For example expiry and heap.
- Build project
mvn clean install
- Create application at cumulocity
POST 'https://{base-url}/application/applications'
Request body:
{
"key": "templates-ehcache",
"name": "templates-ehcache",
"contextPath": "templates-ehcache",
"type": "MICROSERVICE",
"manifest":{},
"requiredRoles": [
"ROLE_INVENTORY_READ",
"ROLE_INVENTORY_CREATE",
"ROLE_INVENTORY_ADMIN",
"ROLE_IDENTITY_READ",
"ROLE_IDENTITY_ADMIN"
],
"roles": [
]
}
-
Subscribe application to your tenant via UI
-
Acquire microservice bootstrap credentials
GET 'https://{base-url}/application/applications/{applicationId}/bootstrapUser
Response body:
{
"password": "************************",
"name": "servicebootstrap_templates-ehcache",
"tenant": "<your tenant>"
}
- Add bootstrap credentials
to your src/main/resources/application-dev.properties
- Start microservice with spring profile "dev"
java -Dspring.profiles.active=dev -jar cumulocity-microservice-templates-ehcache-0.0.1-SNAPSHOT.jar
These tools are provided as-is and without warranty or support. They do not constitute part of the Software AG product suite. Users are free to use, fork and modify them, subject to the license agreement. While Software AG welcomes contributions, we cannot guarantee to include every contribution in the master project.
For more information you can Ask a Question in the TECHcommunity Forums.
You can find additional information in the Software AG TECHcommunity.
Contact us at TECHcommunity if you have any questions.