Package org.kiwiproject.jersey.client
Class RegistryAwareClient
- java.lang.Object
-
- org.kiwiproject.jersey.client.RegistryAwareClient
-
- All Implemented Interfaces:
javax.ws.rs.client.Client
,javax.ws.rs.core.Configurable<javax.ws.rs.client.Client>
public class RegistryAwareClient extends Object implements javax.ws.rs.client.Client
An extension of the JAX-RSClient
interface that provides additionaltarget(...)
methods that will find service instances from a registry, e.g. Consul.
-
-
Constructor Summary
Constructors Constructor Description RegistryAwareClient(javax.ws.rs.client.Client client, org.kiwiproject.registry.client.RegistryClient registryClient)
RegistryAwareClient(javax.ws.rs.client.Client client, org.kiwiproject.registry.client.RegistryClient registryClient, Supplier<Map<String,Object>> headersSupplier)
Creates a newRegistryAwareClient
with the givenClient
,RegistryClient
andSupplier
that will be used to automatically attach request headers to all requests made by this client.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.ws.rs.client.Client
client()
Return the underlying "raw" JAX-RSClient
instance.javax.ws.rs.client.WebTarget
targetForService(String serviceName)
Provide aWebTarget
by looking up a service in the registry using the given service name.javax.ws.rs.client.WebTarget
targetForService(String serviceName, org.kiwiproject.registry.model.Port.PortType portType)
Provide aWebTarget
by looking up a service in the registry using the given service name andPort.PortType
.javax.ws.rs.client.WebTarget
targetForService(ServiceIdentifier identifier)
Provide aWebTarget
by looking up a service in the registry using the given service identifier.javax.ws.rs.client.WebTarget
targetForService(ServiceIdentifier originalIdentifier, org.kiwiproject.registry.model.Port.PortType portType)
Provide aWebTarget
by looking up a service in the registry using the givenServiceIdentifier
andPortType
.javax.ws.rs.client.WebTarget
targetForService(ServiceIdentifier original, org.kiwiproject.registry.model.Port.PortType portType, Function<org.kiwiproject.registry.model.ServiceInstance,String> pathResolver)
Provide aWebTarget
by looking up a service in the registry using the given service identifier.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
RegistryAwareClient
public RegistryAwareClient(javax.ws.rs.client.Client client, org.kiwiproject.registry.client.RegistryClient registryClient)
- Parameters:
client
- the Jersey client to useregistryClient
- the registry lookup client
-
RegistryAwareClient
public RegistryAwareClient(javax.ws.rs.client.Client client, org.kiwiproject.registry.client.RegistryClient registryClient, @Nullable Supplier<Map<String,Object>> headersSupplier)
Creates a newRegistryAwareClient
with the givenClient
,RegistryClient
andSupplier
that will be used to automatically attach request headers to all requests made by this client.If
headersSupplier
isnull
, it is ignored.- Parameters:
client
- the Jersey client to useregistryClient
- the registry lookup clientheadersSupplier
- a supplier of headers to attach to requests, may benull
-
-
Method Detail
-
client
public javax.ws.rs.client.Client client()
Return the underlying "raw" JAX-RSClient
instance. Generally won't be needed but this provides an "escape hatch" if it is needed for some reason. Use wisely, sparingly, or not at all...- Returns:
- the underlying "raw" JAX-RS
Client
-
targetForService
public javax.ws.rs.client.WebTarget targetForService(String serviceName)
Provide aWebTarget
by looking up a service in the registry using the given service name. Finds the latest available version. If more than one instance is found, then one of them is randomly chosen.Note: The returned
WebTarget
will always be set up to access the application port on the service.- Parameters:
serviceName
- the service name in the registry- Returns:
- a
WebTarget
for a randomly selected service instance - See Also:
targetForService(String, PortType)
,targetForService(ServiceIdentifier)
-
targetForService
public javax.ws.rs.client.WebTarget targetForService(String serviceName, org.kiwiproject.registry.model.Port.PortType portType)
Provide aWebTarget
by looking up a service in the registry using the given service name andPort.PortType
. Finds the latest available version. If more than one instance is found, then one of them is randomly chosen.- Parameters:
serviceName
- the service name in the registryportType
- the type of port to connect to- Returns:
- a
WebTarget
for a randomly selected service instance - See Also:
targetForService(ServiceIdentifier)
-
targetForService
public javax.ws.rs.client.WebTarget targetForService(ServiceIdentifier originalIdentifier, org.kiwiproject.registry.model.Port.PortType portType)
Provide aWebTarget
by looking up a service in the registry using the givenServiceIdentifier
andPortType
. Finds the latest available version. If more than one instance is found, then one of them is randomly chosen.- Parameters:
originalIdentifier
- the original identifier that will be adjusted with the given port typeportType
- the port type to use for theWebTarget
- Returns:
- a
WebTarget
for a randomly selected service instance - See Also:
targetForService(ServiceIdentifier)
-
targetForService
public javax.ws.rs.client.WebTarget targetForService(ServiceIdentifier identifier)
Provide aWebTarget
by looking up a service in the registry using the given service identifier. If more than one instance is found, then one of them is randomly chosen.Note: By specifying the connector as
Port.PortType.ADMIN
inidentifier
theWebTarget
will be set up to access the admin port on the service.- Parameters:
identifier
- uniquely identifies the service- Returns:
- a
WebTarget
for a randomly selected service instance
-
targetForService
public javax.ws.rs.client.WebTarget targetForService(ServiceIdentifier original, org.kiwiproject.registry.model.Port.PortType portType, Function<org.kiwiproject.registry.model.ServiceInstance,String> pathResolver)
Provide aWebTarget
by looking up a service in the registry using the given service identifier. If more than one instance is found, then one of them is randomly chosen. The givenpathResolver
function allows a path to be chosen from theServiceInstance
and added to theWebTarget
path.- Parameters:
original
- the originalServiceIdentifier
used to lookup a serviceportType
- the port type (APPLICATION or ADMIN) to use for the WebTarget portpathResolver
- a function to resolve the path to use from the ServiceInstance- Returns:
- a
WebTarget
for a randomly selected service instance
-
-