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": "Requests the target address of a microservice instance selected by the microservice registry.",
"slots": [
{
"key": "1",
"name": "MICRO_SERVICE_ID",
"direction": "REQUEST",
"mandatory": "true",
"type": "ID",
"description": "The ID of the microservice for which an instance is being searched."
},
{
"key": "2",
"name": "OWNER",
"direction": "ANSWER",
"mandatory": "false",
"type": "TARGET_ADDRESS",
"description": "The address of the microservice instance selected by the microservice registry."
}
]
}
Message Arguments
| Key | Name | Direction | Mandatory | Type | Description |
|---|---|---|---|---|---|
| 1 | MICRO_SERVICE_ID | REQUEST | true | ID | The ID of the microservice for which an instance is being searched. |
| 2 | OWNER | ANSWER | false | TARGET_ADDRESS | The address of the microservice instance selected by the microservice registry. |
Usage
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;
}
Record Usage
In
One or more descriptions of these Records are stored in the JSON or XML format
as record.json or record.xml within a directory.
The Record Generator, an included Swing tool, generates helper classes from these files.
These classes can then be used to type-safely write or read messages.