<dependency> <groupId>io.github.springwolf</groupId> <artifactId>springwolf-core</artifactId> <version>0.6.0</version> </dependency> <dependency> <groupId>io.github.springwolf</groupId> <artifactId>springwolf-kafka</artifactId> <version>0.6.0</version> </dependency>
springwolf: enabled: true docket: base-package: com.example.demo info: title: 示例服务 version: 1.0.0 description: SpringWolf 示例服务 plugin: kafka: enabled: true
@Service @RequiredArgsConstructor public class UserEventProducer { private final KafkaTemplate<String, UserEvent> kafkaTemplate; @AsyncPublisher( channelName = "user-events", description = "用户事件发布" ) public void sendUserEvent(UserEvent event) { kafkaTemplate.send("user-events", event.getUserId(), event); } }
@Service @Slf4j public class UserEventConsumer { @AsyncListener( channelName = "user-events", description = "用户事件处理" ) @KafkaListener(topics = "user-events") public void consume(UserEvent event) { log.info("接收到事件: {}", event); } }
@Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/springwolf/**").hasRole("ADMIN") .and() .httpBasic(); } }
http://localhost:8080/springwolf/asyncapi-ui.html
http://localhost:8080/springwolf/docs