Hi Misja,
in case of creating new threads the tenant-context gets lost, so that the microservice does not know to which tenant to connect anymore and which credentials to use.
However there is an easy way to run a new thread within the tenant-context again.
Therefor you need to use the MicroserviceSubscriptionsService and pass the tenant into the new thread.
Hence I would suggest the following.
- When creating the runnable add the tenant as parameter
C8YS7Agent:
C8YS7Client myClient = new C8YS7Client(myDevice, myTenant);
- When invoking the
C8YS7Agent
use the MicroserviceSubscriptionsService
C8YS7Client:
@Autowired
private MicroserviceSubscriptionsService subscriptionsService;
[...]
subscriptionService.runForTenant(myTenant, () -> {
s7Device = c8yAgent.updateDevice(s7Device);
});
Regards Kai