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

The following examples show how to use org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent. 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: InstanceRegistryTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Test
public void testInternalCancel() throws Exception {
	// calling tested method
	instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
	// event of proper type is registered
	assertThat(this.testEvents.applicationEvents.size()).isEqualTo(1);
	assertThat(this.testEvents.applicationEvents
			.get(0) instanceof EurekaInstanceCanceledEvent).isTrue();
	// event details are correct
	final EurekaInstanceCanceledEvent registeredEvent = (EurekaInstanceCanceledEvent) (this.testEvents.applicationEvents
			.get(0));
	assertThat(registeredEvent.getAppName()).isEqualTo(APP_NAME);
	assertThat(registeredEvent.getServerId()).isEqualTo(HOST_NAME);
	assertThat(registeredEvent.getSource()).isEqualTo(instanceRegistry);
	assertThat(registeredEvent.isReplication()).isFalse();
}
 
Example #2
Source File: GemFrameEurekaListener.java    From gem with MIT License 5 votes vote down vote up
@EventListener //服务下线事件
public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {
    //服务断线事件
    String appName = eurekaInstanceCanceledEvent.getAppName();
    String serverId = eurekaInstanceCanceledEvent.getServerId();
    System.out.println("服务断线事件:"+appName+":"+serverId);
}
 
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 listenDown(EurekaInstanceCanceledEvent event) {
    InstanceRegistry registry = (InstanceRegistry) event.getSource();
    com.netflix.appinfo.InstanceInfo instanceInfo =
            registry.getApplication(event.getAppName()).getByInstanceId(event.getServerId());
    InstanceStatus instanceStatus = EurekaInstatnceTransformer.toGrayInstanceStatus(instanceInfo.getStatus());
    sendNotice(instanceInfo, instanceStatus, "DOWN");
}
 
Example #4
Source File: InstanceRegistryTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
@Test
public void testInternalCancel() throws Exception {
	// calling tested method
	instanceRegistry.internalCancel(APP_NAME, HOST_NAME, false);
	// event of proper type is registered
	assertEquals(1, this.testEvents.applicationEvents.size());
	assertTrue(this.testEvents.applicationEvents.get(0) instanceof EurekaInstanceCanceledEvent);
	// event details are correct
	final EurekaInstanceCanceledEvent registeredEvent =
			(EurekaInstanceCanceledEvent) (this.testEvents.applicationEvents.get(0));
	assertEquals(APP_NAME, registeredEvent.getAppName());
	assertEquals(HOST_NAME, registeredEvent.getServerId());
	assertEquals(instanceRegistry, registeredEvent.getSource());
	assertFalse(registeredEvent.isReplication());
}
 
Example #5
Source File: EurekaInstanceCanceledListener.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Translates service instance Eureka metadata from older versions to the current version
 */
@EventListener
public void listen(EurekaInstanceCanceledEvent event) {
    gatewayNotifier.serviceUpdated(EurekaUtils.getServiceIdFromInstanceId(event.getServerId()), null);
}
 
Example #6
Source File: EurekaInstanceCanceledListenerTest.java    From api-layer with Eclipse Public License 2.0 4 votes vote down vote up
private EurekaInstanceCanceledEvent createEvent(String serverId) {
    EurekaInstanceCanceledEvent out = mock(EurekaInstanceCanceledEvent.class);
    when(out.getServerId()).thenReturn(serverId);

    return out;
}
 
Example #7
Source File: InstanceRegistry.java    From didi-eureka-server with MIT License 4 votes vote down vote up
private void handleCancelation(String appName, String id, boolean isReplication) {
	log("cancel " + appName + ", serverId " + id + ", isReplication " + isReplication);
	publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
}
 
Example #8
Source File: InstanceRegistryTest.java    From didi-eureka-server with MIT License 4 votes vote down vote up
@EventListener(EurekaInstanceCanceledEvent.class)
public void onEvent(EurekaInstanceCanceledEvent event) {
	this.applicationEvents.add(event);
}
 
Example #9
Source File: InstanceRegistry.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
private void handleCancelation(String appName, String id, boolean isReplication) {
	log("cancel " + appName + ", serverId " + id + ", isReplication "
			+ isReplication);
	publishEvent(new EurekaInstanceCanceledEvent(this, appName, id, isReplication));
}
 
Example #10
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);
}