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

io.github.springwolf.plugins.stomp.asyncapi.scanners.common.SendToUtil Maven / Gradle / Ivy

Go to download

Automated JSON API documentation for STOMP listeners (websocket) built with Spring

The newest version!
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.plugins.stomp.asyncapi.scanners.common;

import io.github.springwolf.asyncapi.v3.bindings.ChannelBinding;
import io.github.springwolf.asyncapi.v3.bindings.MessageBinding;
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.bindings.stomp.StompChannelBinding;
import io.github.springwolf.asyncapi.v3.bindings.stomp.StompMessageBinding;
import io.github.springwolf.asyncapi.v3.bindings.stomp.StompOperationBinding;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.util.StringValueResolver;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

@Slf4j
public class SendToUtil {

    public static String getChannelName(SendTo annotation, StringValueResolver stringValueResolver) {
        Stream destinations = Arrays.stream(annotation.value());
        List resolvedDestinations =
                destinations.map(stringValueResolver::resolveStringValue).collect(toList());

        log.debug("Found destinations: {}", String.join(", ", resolvedDestinations));
        return resolvedDestinations.get(0);
    }

    public static Map buildChannelBinding() {
        return Map.of("stomp", new StompChannelBinding());
    }

    public static Map buildOperationBinding(
            SendTo annotation, StringValueResolver stringValueResolver) {
        StompOperationBinding binding = new StompOperationBinding();
        return Map.of("stomp", binding);
    }

    public static Map buildMessageBinding() {
        return Map.of("stomp", new StompMessageBinding());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy