1

我正在Spring雲數據流上實現一個流應用程序。我想使用基於Avro的架構註冊表客戶端進行序列化和架構控制。 我的基本目標是爲Source應用程序提供一些外部數據,將其轉換爲準備好的基於avro的模式並將其發送到只接受此模式的Sink應用程序。 我想使用來自外部模式註冊表服務器的模式,而不是模式的文件版本。 我的代碼如下所示:在Spring雲數據流中激活Avro消息轉換器

@EnableBinding(Source.class) 
@EnableSchemaRegistryClient 
public class DisSampleSource { 

    private final DisSampleSourceProperties properties; 

    @Inject 
    public DisSampleSource(DisSampleSourceProperties properties) { 
     this.properties = properties; 
    } 

    @InboundChannelAdapter(Source.OUTPUT) 
    public String feed() throws IOException { 
     if (!Paths.get(properties.getPath()).toFile().exists()) { 
      throw new InvalidPathException(this.properties.getPath(), 
        "The file does not exists or is of not proper type."); 
     } 
     return new String(Files.readAllBytes(Paths.get(properties.getPath())), StandardCharsets.UTF_8); 
    } 
} 

POM:

<dependency> 
     <groupId>org.springframework.cloud</groupId> 
     <artifactId>spring-cloud-stream-schema</artifactId> 
     <version>1.1.1.RELEASE</version> 
    </dependency> 

在啓動應用程序,我通過性能:

--spring.cloud.stream.bindings.output.contentType=application/foo.bar.v1+avro 

目前,該應用程序無法啓動與以下情況除外:

2017-02-13 16:25:30.430 WARN 2444 --- [   main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'disSampleSource' defined in URL [jar:file:/D:/git/dis/sample/source/target/dis-sample-source-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/atsisa/bit/dis/sample/DisSampleSource.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.stream.config.ChannelBindingAutoConfiguration': Unsatisfied dependency expressed through field 'adapters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.stream.messaging.Source': Invocation of init method failed; nested exception is org.springframework.cloud.stream.converter.ConversionException: No message converter is registered for application/foo.bar.v1+avro 
2017-02-13 16:25:30.440 INFO 2444 --- [   main] o.apache.catalina.core.StandardService : Stopping service Tomcat 
2017-02-13 16:25:30.480 INFO 2444 --- [   main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 
2017-02-13 16:25:30.485 ERROR 2444 --- [   main] o.s.boot.SpringApplication    : Application startup failed 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'disSampleSource' defined in URL [jar:file:/D:/git/dis/sample/source/target/dis-sample-source-1.0.0-SNAPSHOT.jar!/BOOT-INF/classes!/com/atsisa/bit/dis/sample/DisSampleSource.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.stream.config.ChannelBindingAutoConfiguration': Unsatisfied dependency expressed through field 'adapters'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cloud.stream.messaging.Source': Invocation of init method failed; nested exception is org.springframework.cloud.stream.converter.ConversionException: No message converter is registered for application/foo.bar.v1+avro 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE] 

我在做什麼錯?

回答

0

Avro是春季雲流模式的一個可選的依賴(如意圖是支持其他格式的未來。爲了激活模式支持,你應該簡單地添加

<dependency> 
    <groupId>org.apache.avro</groupId> 
    <artifactId>avro</artifactId> 
    <version>1.8.1</version> 
</dependency> 

到項目中。

+1

我們絕對可以考慮通過啓動器添加Avro支持 - 請參閱https://github.com/spring-cloud/spring-cloud-stream/issues/798 –