public void sendNotification(@NotNull CreateNotificationDto newNotification) {
        if (!config.isEnabled()) {
            LOGGER.trace("Notifications subsystem is disabled. Notification {0} will not be sent", newNotification);
            return;
        }

        LOGGER.debug("Creating new notification(s): {0}", newNotification);

        List<UserDto> resolvedRecipients = calculateRecipients(newNotification.getRecipient());

        for (UserDto resolvedRecipient : resolvedRecipients) {
            NotificationEntity notificationEntity = new NotificationEntity()
                 .setCategory(newNotification.getCategory())
                 .setReason(newNotification.getReason())
                 .setReasonMessage(newNotification.getReasonMessage())
                 .setStatus(NotificationStatus.OPEN)
                 .setRecipient(resolvedRecipient.getUsername())
                 .setSource(newNotification.getSource())
                 .setPayload(JsonUtil.toJsonTree(newNotification.getPayload()));

            tryAction(() -> {
                // 1. Save notification into notifications table.
                LOGGER.trace("Creating notification entity in repository layer: {0}", notificationEntity);
                notificationRepository.create(notificationEntity);

                // Avoiding serializing and deserializing the payload immediately!
                NotificationDto<?> dto = toDto(notificationEntity, newNotification.getPayload(), resolvedRecipient);

                // 2. Emit notification onto notification bus.
                LOGGER.trace("Firing notification: {0}", dto);
                notificationDispatcher.fireAsync(dto)
                        .whenCompleteAsync((res, throwable) -> {
                            if (throwable != null) {
                                LOGGER.error(throwable, "An error occurred in the asynchronous part of the notification subsystem. "
                                                                + "This error likely did not return directly to the requester: {0}", throwable.getMessage());
                            }
                        });
            });
        }
    }
Send a new notification to a specified recipient (userId)

@param newNotification the new notification.
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/NotificationService.java