Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
714741b1
Commit
714741b1
authored
Oct 03, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added serviceId to ServiceInstance;
added beginnings of a generic DiscoveryClient interface;
parent
66e0c643
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
7 deletions
+72
-7
ServiceInstance.java
...ava/org/springframework/cloud/client/ServiceInstance.java
+1
-0
DiscoveryClient.java
...ringframework/cloud/client/discovery/DiscoveryClient.java
+13
-0
EurekaDiscoverClient.java
...g/springframework/cloud/netflix/EurekaDiscoverClient.java
+35
-0
EurekaClientConfiguration.java
...ework/cloud/netflix/eureka/EurekaClientConfiguration.java
+9
-3
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+9
-2
EurekaRibbonInitializer.java
.../cloud/netflix/ribbon/eureka/EurekaRibbonInitializer.java
+5
-2
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/client/ServiceInstance.java
View file @
714741b1
...
...
@@ -6,6 +6,7 @@ package org.springframework.cloud.client;
* TODO: name? Server? HostAndPort? Instance?
*/
public
interface
ServiceInstance
{
public
String
getServiceId
();
public
String
getHost
();
public
int
getPort
();
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/client/discovery/DiscoveryClient.java
0 → 100644
View file @
714741b1
package
org
.
springframework
.
cloud
.
client
.
discovery
;
import
org.springframework.cloud.client.ServiceInstance
;
/**
* @author Spencer Gibb
*/
public
interface
DiscoveryClient
{
/**
* @return ServiceInstance with information used to register the local service
*/
public
ServiceInstance
getLocalServiceInstance
();
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/EurekaDiscoverClient.java
0 → 100644
View file @
714741b1
package
org
.
springframework
.
cloud
.
netflix
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
/**
* @author Spencer Gibb
*/
public
class
EurekaDiscoverClient
implements
DiscoveryClient
{
@Autowired
private
EurekaInstanceConfigBean
config
;
@Override
public
ServiceInstance
getLocalServiceInstance
()
{
return
new
ServiceInstance
()
{
@Override
public
String
getServiceId
()
{
return
config
.
getAppname
();
}
@Override
public
String
getHost
()
{
return
config
.
getHostname
();
}
@Override
public
int
getPort
()
{
return
config
.
getNonSecurePort
();
}
};
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfiguration.java
View file @
714741b1
...
...
@@ -27,6 +27,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.netflix.EurekaDiscoverClient
;
import
org.springframework.cloud.netflix.servo.ServoMetricReader
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.SmartLifecycle
;
...
...
@@ -40,7 +42,6 @@ import org.springframework.core.Ordered;
import
com.netflix.appinfo.ApplicationInfoManager
;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.discovery.DiscoveryClient
;
import
com.netflix.discovery.DiscoveryManager
;
import
com.netflix.discovery.EurekaClientConfig
;
...
...
@@ -128,16 +129,21 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Bean
@Lazy
@Scope
(
proxyMode
=
ScopedProxyMode
.
TARGET_CLASS
)
public
DiscoveryClient
d
iscoveryClient
()
{
public
com
.
netflix
.
discovery
.
DiscoveryClient
eurekaD
iscoveryClient
()
{
return
DiscoveryManager
.
getInstance
().
getDiscoveryClient
();
}
@Bean
public
DiscoveryClient
discoveryClient
()
{
return
new
EurekaDiscoverClient
();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
MBeanServer
.
class
)
public
EurekaHealthIndicator
eurekaHealthIndicator
(
MBeanServer
server
,
EurekaInstanceConfig
config
)
{
return
new
EurekaHealthIndicator
(
d
iscoveryClient
(),
return
new
EurekaHealthIndicator
(
eurekaD
iscoveryClient
(),
new
ServoMetricReader
(
server
),
config
);
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
714741b1
...
...
@@ -22,17 +22,24 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
if
(
server
==
null
)
{
throw
new
IllegalStateException
(
"Unable to locate ILoadBalancer for service: "
+
serviceId
);
}
return
new
RibbonServer
(
server
);
return
new
RibbonServer
(
serv
iceId
,
serv
er
);
}
private
class
RibbonServer
implements
ServiceInstance
{
private
String
serviceId
;
private
Server
server
;
private
RibbonServer
(
Server
server
)
{
private
RibbonServer
(
String
serviceId
,
Server
server
)
{
this
.
serviceId
=
serviceId
;
this
.
server
=
server
;
}
@Override
public
String
getServiceId
()
{
return
serviceId
;
}
@Override
public
String
getHost
()
{
return
server
.
getHost
();
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonInitializer.java
View file @
714741b1
...
...
@@ -4,6 +4,8 @@ import com.netflix.config.ConfigurationManager;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
;
import
org.springframework.cloud.netflix.ribbon.ServerListInitializer
;
import
static
com
.
netflix
.
client
.
config
.
CommonClientConfigKey
.*;
/**
* @author Spencer Gibb
*/
...
...
@@ -12,8 +14,9 @@ public class EurekaRibbonInitializer implements ServerListInitializer {
@Override
public
void
initialize
(
String
serviceId
)
{
//TODO: should this look more like hibernate spring boot props?
setProp
(
serviceId
,
"NIWSServerListClassName"
,
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
setProp
(
serviceId
,
"DeploymentContextBasedVipAddresses"
,
serviceId
);
//FIXME: what should this be?
//TODO: only set the property if it hasn't already been set?
setProp
(
serviceId
,
NIWSServerListClassName
.
key
(),
DiscoveryEnabledNIWSServerList
.
class
.
getName
());
setProp
(
serviceId
,
DeploymentContextBasedVipAddresses
.
key
(),
serviceId
);
//FIXME: what should this be?
}
protected
void
setProp
(
String
serviceId
,
String
suffix
,
String
value
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment