@Override
    public void handleRegisteredServiceExpiredEvent(final CasRegisteredServiceExpiredEvent event) {
        val registeredService = event.getRegisteredService();
        val contacts = registeredService.getContacts();
        val serviceRegistry = casProperties.getServiceRegistry();
        val serviceName = StringUtils.defaultIfBlank(registeredService.getName(), registeredService.getServiceId());
        if (contacts == null || contacts.isEmpty()) {
            LOGGER.debug("No contacts are defined to be notified for policy changes to service [{}]", serviceName);
            return;
        }

        val logMessage = String.format("Sending notification to [{}] as service [{}] is %s from registry", event.isDeleted() ? "deleted" : "expired");
        LOGGER.info(logMessage, contacts, serviceName);

        communicationsManager.validate();
        if (communicationsManager.isMailSenderDefined()) {
            val mail = serviceRegistry.getMail();
            val body = EmailMessageBodyBuilder.builder()
                .properties(mail)
                .parameters(Map.of("service", serviceName))
                .build().get();

            contacts
                .stream()
                .filter(contact -> StringUtils.isNotBlank(contact.getEmail()))
                .forEach(contact -> {
                    val emailRequest = EmailMessageRequest.builder()
                        .emailProperties(mail)
                        .to(List.of(contact.getEmail()))
                        .tenant(event.getClientInfo().getTenant())
                        .body(body).build();
                    communicationsManager.email(emailRequest);
                });
        }
        if (communicationsManager.isSmsSenderDefined()) {
            val sms = serviceRegistry.getSms();
            val message = SmsBodyBuilder.builder().properties(sms).parameters(Map.of("service", serviceName)).build().get();
            contacts
                .stream()
                .filter(contact -> StringUtils.isNotBlank(contact.getPhone()))
                .forEach(Unchecked.consumer(contact -> {
                    val recipients = new ArrayList<>(org.springframework.util.StringUtils.commaDelimitedListToSet(contact.getPhone()));
                    val smsRequest = SmsRequest.builder()
                        .from(sms.getFrom())
                        .to(recipients)
                        .text(message)
                        .build();
                    communicationsManager.sms(smsRequest);
                }));
        }
    }
This is {@link DefaultRegisteredServicesEventListener}.

@author Misagh Moayyed
@since 5.1.0
core/cas-server-core-services-api/src/main/java/org/apereo/cas/services/DefaultRegisteredServicesEventListener.java