gpt4 book ai didi

spring-boot - 如何使用 Azure 事件中心创建 Spring Boot 应用程序

转载 作者:行者123 更新时间:2023-12-03 07:08:29 33 4
gpt4 key购买 nike

当我的应用程序运行时遇到错误我的应用程序中的所有类都可以在下面看到

任何修复此错误的助手

我的项目中只有 3 个类可用。

 Failed to start bean 'outputBindingLifecycle'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eventHubChannelProvisioner' defined in com.azure.spring.eventhub.stream.binder.config.EventHubBinderConfiguration: Unsatisfied dependency expressed through method 'eventHubChannelProvisioner' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.azure.spring.integration.eventhub.factory.EventHubConnectionStringProvider' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

如何解决这个我的主类

import com.azure.spring.integration.core.EventHubHeaders;
import com.azure.spring.integration.core.api.reactor.Checkpointer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;

import java.util.function.Consumer;

import static com.azure.spring.integration.core.AzureHeaders.CHECKPOINTER;

@SpringBootApplication
public class EventHubsCheckerApplication {

public static final Logger LOGGER = LoggerFactory.getLogger(EventHubsCheckerApplication.class);

public static void main(String[] args) {
SpringApplication.run(EventHubsCheckerApplication.class, args);
}

@Bean
public Consumer<Message<String>> consume() {
return message -> {
Checkpointer checkpointer = (Checkpointer) message.getHeaders().get(CHECKPOINTER);
LOGGER.info("New message received: '{}', partition key: {}, sequence number: {}, offset: {}, enqueued time: {}",
message.getPayload(),
message.getHeaders().get(EventHubHeaders.PARTITION_KEY),
message.getHeaders().get(EventHubHeaders.SEQUENCE_NUMBER),
message.getHeaders().get(EventHubHeaders.OFFSET),
message.getHeaders().get(EventHubHeaders.ENQUEUED_TIME)
);
checkpointer.success()
.doOnSuccess(success -> LOGGER.info("Message '{}' successfully checkpointed", message.getPayload()))
.doOnError(error -> LOGGER.error("Exception found", error))
.subscribe();
};
}
}

Controller 类

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Sinks;

@RestController
public class EventProducerController {

public static final Logger LOGGER = LoggerFactory.getLogger(EventProducerController.class);

@Autowired
private Sinks.Many<Message<String>> many;

@PostMapping("/messages")
public ResponseEntity<String> sendMessage(@RequestParam String message) {
LOGGER.info("Going to add message {} to sendMessage.", message);
many.emitNext(MessageBuilder.withPayload(message).build(), Sinks.EmitFailureHandler.FAIL_FAST);
return ResponseEntity.ok(message);
}
}

配置类

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.Message;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Sinks;

import java.util.function.Supplier;

@Configuration
public class EventProducerConfiguration {

private static final Logger LOGGER = LoggerFactory.getLogger(EventProducerConfiguration.class);

@Bean
public Sinks.Many<Message<String>> many() {
return Sinks.many().unicast().onBackpressureBuffer();
}

@Bean
public Supplier<Flux<Message<String>>> supply(Sinks.Many<Message<String>> many) {
return () -> many.asFlux()
.doOnNext(m -> LOGGER.info("Manually sending message {}", m))
.doOnError(t -> LOGGER.error("Error encountered", t));
}
}

pom文件

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.contoso</groupId>
<artifactId>event-hubs-cheker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>event-hubs-cheker</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-cloud-stream-binder-eventhubs</artifactId>
<version>2.12.0</version>
</dependency>

</dependencies>

如何运行而不出现任何错误,我无法修复此问题,请帮助我

如何解决此问题我尝试解决此问题,但无法解决

最佳答案

按照以下网页上的说明进行操作后:How to create a Spring Cloud Stream Binder application with Azure Event Hubs

我能够让该项目正常运行。您可以在以下 GitHub 存储库中查看我的实现:https://github.com/esalomon/spring-event-hubs1

关于spring-boot - 如何使用 Azure 事件中心创建 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70968419/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com