CRecordGetMicroServiceInstance
This message is used when you need the address of an instance of a microservice.
This message belongs to the microservice registry API.
{
"id": "ddadb3e0-98b9-4e59-849d-369b079cbc1d",
"name": "GET_MICRO_SERVICE_INSTANCE",
"isService": "false",
"description": "Get the target address of the given microservice ID.\nIf more than one instance is registered, a random instance is chosen.",
"slots": [
{
"key": "1",
"name": "MICRO_SERVICE_ID",
"direction": "REQUEST",
"mandatory": "true",
"type": "ID",
"description": "The microservice to search for."
},
{
"key": "2",
"name": "OWNER",
"direction": "ANSWER",
"mandatory": "false",
"type": "TARGET_ADDRESS",
"description": "An address of the microservice."
}
]
}
Example of use (after generating of the class CRecordGetMicroServiceInstance):
constructor:
addMessageHandler(CRecordGetMicroServiceInstance.ID,
this::asyncGetInstance);
// request
private void getMicroServiceInstance(@NotNull final CTargetAddress aAddressOfMicroserviceRegistry,
@NotNull final IId aMicroserviceId) throws CException
{
final CEnvelope env = CEnvelope.forSingleTarget(aAddressOfMicroserviceRegistry);
final CRecord rec = CRecordGetMicroServiceInstance.create();
CRecordGetMicroServiceInstance.setMicroServiceId(rec,
aMicroserviceId);
sendRequest(env,
rec);
}
// handle answer
private boolean asyncGetInstance(@NotNull final CEnvelope aEnvelope,
@NotNull final CRecord aRecord)
{
if (aEnvelope.isAnswer())
{
if (aEnvelope.getResultCode() == CResultCode.SUCCESS)
{
final CTargetAddress address = CRecordGetMicroServiceInstance.getOwner(aRecord,
null);
// ...
}
return true;
}
return false;
}