im trying to get the Credentials of UPS in cloud foundry: using:
Mono<ServiceKey> serviceKey = (Mono<ServiceKey>) cloudFoundryOperations
.services()
.getServiceKey(
GetServiceKeyRequest.builder()
.serviceKeyName("digital_cassandra")
.serviceInstanceName("2a5aa377-e992-4f88-9f85-d9cec5c3bea9")
.build())
.subscribe();
serviceKey.map(serviceKey1 -> {
System.out.println(serviceKey1.getCredentials().toString());
return serviceKey1.getCredentials().get(0);
});
but nothing printed. how to fet the serviceKeyName and serviceInstanceName by cloudFoundryOperations? i need to print all the serviceKeyName and serviceInstanceName in my space.
It should be the actual name, not the guid. Like "my-key" or whatever you called your key.
If you just want to print to the console, try something like this:
The GetServiceKeyRequest determines which service key is looked up. The
doOnNext
call allows you to inspect but not consume the key, which works fine to print it out. Then the example calls.block()
to wait for the results, which is fine cause this is just an example. You wouldn't want to do that in your actual code though. You'd probably want one of thesubscribe()
variants (you could swapsubscribe()
fordoOnNext()
too, just depends on what you're code is doing).To get all the keys for all the service instances:
This one is enumerating all the service instances, printing the name/id, then using
flatMap
to go out and get the service keys for each service instance. It then merges them all into oneFlux<ServiceKey>
. ThedoOnNext()
is just for printing. You don't necessarily have to do that. You could consume the result in a number of ways, like collect it into a list or subscribe to it, this just works nicely for an example. Use what works best for your code.