org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent Java Examples

The following examples show how to use org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstanceRegistry.java    From didi-eureka-server with MIT License 6 votes vote down vote up
@Override
public boolean renew(final String appName, final String serverId,
		boolean isReplication) {
	log("renew " + appName + " serverId " + serverId + ", isReplication {}"
			+ isReplication);
	List<Application> applications = getSortedApplications();
	for (Application input : applications) {
		if (input.getName().equals(appName)) {
			InstanceInfo instance = null;
			for (InstanceInfo info : input.getInstances()) {
				if (info.getId().equals(serverId)) {
					instance = info;
					break;
				}
			}
			publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
					instance, isReplication));
			break;
		}
	}
	return super.renew(appName, serverId, isReplication);
}
 
Example #2
Source File: InstanceRegistry.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Override
public boolean renew(final String appName, final String serverId,
		boolean isReplication) {
	log("renew " + appName + " serverId " + serverId + ", isReplication {}"
			+ isReplication);
	List<Application> applications = getSortedApplications();
	for (Application input : applications) {
		if (input.getName().equals(appName)) {
			InstanceInfo instance = null;
			for (InstanceInfo info : input.getInstances()) {
				if (info.getId().equals(serverId)) {
					instance = info;
					break;
				}
			}
			publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId,
					instance, isReplication));
			break;
		}
	}
	return super.renew(appName, serverId, isReplication);
}
 
Example #3
Source File: EurekaInstanceListener.java    From spring-cloud-gray with Apache License 2.0 5 votes vote down vote up
/**
 * 监听eureka实例心跳事件,并发送信息给灰度服务器
 *
 * @param event eureka 实例心跳事件
 */
@EventListener
public void listenRenew(EurekaInstanceRenewedEvent event) {
    com.netflix.appinfo.InstanceInfo instanceInfo = event.getInstanceInfo();
    InstanceStatus instanceStatus = EurekaInstatnceTransformer.toGrayInstanceStatus(instanceInfo.getStatus());
    sendNotice(instanceInfo, instanceStatus, "RENEW");
}
 
Example #4
Source File: InstanceRegistryTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Test
public void testRenew() throws Exception {
	//Creating two instances of the app
	final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME, INSTANCE_ID, PORT, null);
	final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME, "my-host-name:8009", 8009, null);
	// creating application list with an app having two instances
	final Application application = new Application(APP_NAME, Arrays.asList(instanceInfo1, instanceInfo2));
	final List<Application> applications = new ArrayList<>();
	applications.add(application);
	// stubbing applications list
	doReturn(applications).when(instanceRegistry).getSortedApplications();
	// calling tested method
	instanceRegistry.renew(APP_NAME, INSTANCE_ID, false);
	instanceRegistry.renew(APP_NAME, "my-host-name:8009", false);
	// event of proper type is registered
	assertEquals(2, this.testEvents.applicationEvents.size());
	assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceRenewedEvent);
	assertTrue(this.testEvents.applicationEvents.get(1) instanceof EurekaInstanceRenewedEvent);
	// event details are correct
	final EurekaInstanceRenewedEvent event1 = (EurekaInstanceRenewedEvent)
			(this.testEvents.applicationEvents.get(0));
	assertEquals(APP_NAME, event1.getAppName());
	assertEquals(INSTANCE_ID, event1.getServerId());
	assertEquals(instanceRegistry, event1.getSource());
	assertEquals(instanceInfo1, event1.getInstanceInfo());
	assertFalse(event1.isReplication());

	final EurekaInstanceRenewedEvent event2 = (EurekaInstanceRenewedEvent)
			(this.testEvents.applicationEvents.get(1));
	assertEquals(instanceInfo2, event2.getInstanceInfo());
}
 
Example #5
Source File: InstanceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Test
public void testRenew() throws Exception {
	// Creating two instances of the app
	final InstanceInfo instanceInfo1 = getInstanceInfo(APP_NAME, HOST_NAME,
			INSTANCE_ID, PORT, null);
	final InstanceInfo instanceInfo2 = getInstanceInfo(APP_NAME, HOST_NAME,
			"my-host-name:8009", 8009, null);
	// creating application list with an app having two instances
	final Application application = new Application(APP_NAME,
			Arrays.asList(instanceInfo1, instanceInfo2));
	final List<Application> applications = new ArrayList<>();
	applications.add(application);
	// stubbing applications list
	doReturn(applications).when(instanceRegistry).getSortedApplications();
	// calling tested method
	instanceRegistry.renew(APP_NAME, INSTANCE_ID, false);
	instanceRegistry.renew(APP_NAME, "my-host-name:8009", false);
	// event of proper type is registered
	assertThat(this.testEvents.applicationEvents.size()).isEqualTo(2);
	assertThat(this.testEvents.applicationEvents
			.get(0) instanceof EurekaInstanceRenewedEvent).isTrue();
	assertThat(this.testEvents.applicationEvents
			.get(1) instanceof EurekaInstanceRenewedEvent).isTrue();
	// event details are correct
	final EurekaInstanceRenewedEvent event1 = (EurekaInstanceRenewedEvent) (this.testEvents.applicationEvents
			.get(0));
	assertThat(event1.getAppName()).isEqualTo(APP_NAME);
	assertThat(event1.getServerId()).isEqualTo(INSTANCE_ID);
	assertThat(event1.getSource()).isEqualTo(instanceRegistry);
	assertThat(event1.getInstanceInfo()).isEqualTo(instanceInfo1);
	assertThat(event1.isReplication()).isFalse();

	final EurekaInstanceRenewedEvent event2 = (EurekaInstanceRenewedEvent) (this.testEvents.applicationEvents
			.get(1));
	assertThat(event2.getInstanceInfo()).isEqualTo(instanceInfo2);
}
 
Example #6
Source File: GemFrameEurekaListener.java    From gem with MIT License 4 votes vote down vote up
@EventListener // 服务续约事件
public void listen(EurekaInstanceRenewedEvent event) {
	String appName = event.getAppName();
	String serverId = event.getServerId();
	System.out.println("服务续约事件:" + appName + ":" + serverId);
}
 
Example #7
Source File: InstanceRegistryTest.java    From didi-eureka-server with MIT License 4 votes vote down vote up
@EventListener(EurekaInstanceRenewedEvent.class)
public void onEvent(EurekaInstanceRenewedEvent event) {
	this.applicationEvents.add(event);
}
 
Example #8
Source File: InstanceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
@Override
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
	return EurekaInstanceRegisteredEvent.class.isAssignableFrom(eventType)
			|| EurekaInstanceCanceledEvent.class.isAssignableFrom(eventType)
			|| EurekaInstanceRenewedEvent.class.isAssignableFrom(eventType);
}