Getting error in Scheduling method in Cumulocity

Can you try:

public class FluentService {

    @Autowired
    private TenantOptionApi tenantOptionApi;

    @Autowired
    private MicroserviceSubscriptionsService subscriptionsService;

    @Scheduled(fixedDelay = 5000)
    public void pollTenantOptions() {
        subscriptionService.runForTenant("your-tenant-id", () - > {
            OptionPK optionPK = new OptionPK();
            optionPK.setCategory(AuthenticationConstants.TENANT_OPTION_CATEGORY);
            optionPK.setKey("data-mapping");
            OptionRepresentation optionRepresentation
            tenantOptionApi.getOption(optionPK);
            String jsonString = optionRepresentation.getValue();
            System.out.println(jsonString);
            DataMapping dataMapping = JSONParser.defaultJSONParser().parse(DataMapping.class, jsonString);
            System.out.println(dataMapping.toString());
        });
    }
}

I’ve wrapped your code around the MicroserviceSubscriptionsService , this should give your code the tenant scope.

See also: Microservice Client that connect to multiple devices - #2 by Kai_Sieben

2 Likes