All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.stavshamir.springwolf.asyncapi.DefaultChannelsService Maven / Gradle / Ivy

Go to download

Automated JSON API documentation for async APIs (Kafka etc.) interfaces built with Spring

There is a newer version: 1.9.0
Show newest version
package io.github.stavshamir.springwolf.asyncapi;

import com.asyncapi.v2._6_0.model.channel.ChannelItem;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelMerger;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.ChannelsScanner;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Service to detect AsyncAPI channels in the current spring context.
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DefaultChannelsService implements ChannelsService {

    private final List channelsScanners;

    /**
     * Collects all AsyncAPI ChannelItems using the available {@link ChannelsScanner}
     * beans.
     * @return Map of channel names mapping to detected ChannelItems
     */
    @Override
    public Map findChannels() {
        List> foundChannelItems = new ArrayList<>();

        for (ChannelsScanner scanner : channelsScanners) {
            try {
                Map channels = scanner.scan();
                foundChannelItems.addAll(channels.entrySet());
            } catch (Exception e) {
                log.error("An error was encountered during channel scanning with {}: {}", scanner, e.getMessage());
            }
        }
        return ChannelMerger.merge(foundChannelItems);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy