Skip to content

io microsphere spring cloud client service registry aspect EventPublishingRegistrationAspect

github-actions[bot] edited this page Apr 8, 2026 · 3 revisions

EventPublishingRegistrationAspect

Type: Class | Module: microsphere-spring-cloud-commons | Package: io.microsphere.spring.cloud.client.service.registry.aspect | Since: 1.0.0

Source: microsphere-spring-cloud-commons/src/main/java/io/microsphere/spring/cloud/client/service/registry/aspect/EventPublishingRegistrationAspect.java

Overview

Event-Publishing Aspect for Registration.

Declaration

public class EventPublishingRegistrationAspect implements ApplicationContextAware

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.2.9-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

beforeRegister

// This advice is triggered automatically when ServiceRegistry.register() is called:
serviceRegistry.register(registration);
// A RegistrationPreRegisteredEvent is published before the actual registration

beforeDeregister

// This advice is triggered automatically when ServiceRegistry.deregister() is called:
serviceRegistry.deregister(registration);
// A RegistrationPreDeregisteredEvent is published before the actual deregistration

afterRegister

// This advice is triggered automatically after ServiceRegistry.register() completes:
serviceRegistry.register(registration);
// A RegistrationRegisteredEvent is published after the actual registration

afterDeregister

// This advice is triggered automatically after ServiceRegistry.deregister() completes:
serviceRegistry.deregister(registration);
// A RegistrationDeregisteredEvent is published after the actual deregistration

setApplicationContext

// Called automatically by Spring's ApplicationContextAware callback:
aspect.setApplicationContext(applicationContext);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-spring-cloud-commons</artifactId>
    <version>${microsphere-spring-cloud.version}</version>
</dependency>

Tip: Use the BOM (microsphere-spring-cloud-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.spring.cloud.client.service.registry.aspect.EventPublishingRegistrationAspect;

API Reference

Public Methods

Method Description
beforeRegister The pointcut expression for ServiceRegistry#register(Registration).
beforeDeregister AOP advice executed before ServiceRegistry#deregister(Registration), publishing a
afterRegister AOP advice executed after ServiceRegistry#register(Registration), publishing a
afterDeregister AOP advice executed after ServiceRegistry#deregister(Registration), publishing a
setApplicationContext Sets the ApplicationContext used to publish registration events and

Method Details

beforeRegister

public void beforeRegister(ServiceRegistry registry, Registration registration)

The pointcut expression for ServiceRegistry#register(Registration). / public static final String REGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.register(*)) && target(registry) && args(registration)";

/** The pointcut expression for ServiceRegistry#deregister(Registration). / public static final String DEREGISTER_POINTCUT_EXPRESSION = "execution(* org.springframework.cloud.client.serviceregistry.ServiceRegistry.deregister(*)) && target(registry) && args(registration)";

private ApplicationContext context;

private ObjectProvider registrationCustomizers;

/** AOP advice executed before ServiceRegistry#register(Registration), publishing a RegistrationPreRegisteredEvent and applying RegistrationCustomizer customizations.

Example Usage:

`// This advice is triggered automatically when ServiceRegistry.register() is called:
serviceRegistry.register(registration);
// A RegistrationPreRegisteredEvent is published before the actual registration
`

beforeDeregister

public void beforeDeregister(ServiceRegistry registry, Registration registration)

AOP advice executed before ServiceRegistry#deregister(Registration), publishing a RegistrationPreDeregisteredEvent.

Example Usage:

`// This advice is triggered automatically when ServiceRegistry.deregister() is called:
serviceRegistry.deregister(registration);
// A RegistrationPreDeregisteredEvent is published before the actual deregistration
`

afterRegister

public void afterRegister(ServiceRegistry registry, Registration registration)

AOP advice executed after ServiceRegistry#register(Registration), publishing a RegistrationRegisteredEvent.

Example Usage:

`// This advice is triggered automatically after ServiceRegistry.register() completes:
serviceRegistry.register(registration);
// A RegistrationRegisteredEvent is published after the actual registration
`

afterDeregister

public void afterDeregister(ServiceRegistry registry, Registration registration)

AOP advice executed after ServiceRegistry#deregister(Registration), publishing a RegistrationDeregisteredEvent.

Example Usage:

`// This advice is triggered automatically after ServiceRegistry.deregister() completes:
serviceRegistry.deregister(registration);
// A RegistrationDeregisteredEvent is published after the actual deregistration
`

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)

Sets the ApplicationContext used to publish registration events and to look up RegistrationCustomizer instances.

Example Usage:

`// Called automatically by Spring's ApplicationContextAware callback:
aspect.setApplicationContext(applicationContext);
`

See Also

  • RegistrationPreRegisteredEvent
  • RegistrationRegisteredEvent
  • RegistrationPreDeregisteredEvent
  • RegistrationDeregisteredEvent

This documentation was auto-generated from the source code of microsphere-spring-cloud.

Home

spring-cloud-commons

spring-cloud-openfeign

Clone this wiki locally