Search code examples
javaapache-kafkaspring-cloud-gateway

Spring Cloud Gateway with Kafka Broadcaster


I am working on a project and working on spring-cloud-gateway and kafka broadcaster. The project uses spring-cloud-gateway, so that means that there is no any controller. The requests are being forwarded to another microservice by using spring-cloud-gateway.

My problem is that I need to send a message to a kafka topic. I know that there are some examples about amazon sqs and sns with spring-cloud-gateway. Is there any example for using of kafka and spring-cloud-gateway?


Solution

  • You can use this tutorial

    @SpringBootApplication
    @EnableWebSocketMessageBroker
    public class MicroserviceWebApplication extends AbstractWebSocketMessageBrokerConfigurer {
        public static void main(String[] args) {
            System.setProperty("spring.devtools.restart.enabled", "true");
            SpringApplication.run(MicroserviceWebApplication.class, args);
        }
       @Override
        public void configureMessageBroker(MessageBrokerRegistry config) {
            config.enableSimpleBroker("/topic");
            config.setApplicationDestinationPrefixes("/app");
        }
    
        @Override
        public void registerStompEndpoints(StompEndpointRegistry registry) {
    
            registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
        }
    }