Spring Integration: Невозможно провести выборы лидера с хранителем зоопарка - PullRequest
1 голос
/ 02 мая 2019

Я пытаюсь выбрать лидера среди контейнеров моего приложения, чтобы выполнить какое-то задание

Я написал следующий код,

@Configuration
@EnableIntegration
public class LeaderConfiguration {

  @Bean
  public LeaderInitiatorFactoryBean leaderInitiator(CuratorFramework client) {
   return new LeaderInitiatorFactoryBean()
        .setClient(client)
        .setPath("/app/test/")
        .setRole("app");
  }


  @Bean
  @Primary
  CuratorFrameworkFactoryBean curatorFramework() {
    return new CuratorFrameworkFactoryBean("127.0.0.1:2181");
  }

  @Bean
  @InboundChannelAdapter(channel = "attributeChannel", autoStartup = "false", poller = @Poller(fixedDelay = "100"))
  @Role("app")
  public Supplier<String> inboundChannelAdapter() {
    return () -> "app";
  }

  @Bean("attributeChannel")
  public MessageChannel attributeChannel() {
    return new DirectChannel();
  }

  @ServiceActivator(inputChannel = "attributeChannel", autoStartup = "false")
  public void listen(Object a) {
    System.out.println("I am leader");
  }

}

У меня есть следующие зависимости

plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.example.zookeeper'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-integration'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'

    // https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-zookeeper
    compile group: 'org.springframework.integration', name: 'spring-integration-zookeeper', version: '5.1.4.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-zookeeper-core
    //compile group: 'org.springframework.cloud', name: 'spring-cloud-zookeeper-core', version: '2.1.0.RELEASE'



    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

Мой местный зоопарк запущен и работает.

Я получаю сообщение об ошибке, возможно, мои настройки соединения неверны

019-05-02 19:08:57.178  INFO 38709 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager     : State change: RECONNECTED
2019-05-02 19:08:57.180  INFO 38709 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn          : Unable to read additional data from server sessionid 0x10006f79d980001, likely server has closed socket, closing socket connection and attempting reconnect
2019-05-02 19:08:57.285  INFO 38709 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager     : State change: SUSPENDED
2019-05-02 19:08:58.808  INFO 38709 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn          : Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2019-05-02 19:08:58.808  INFO 38709 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn          : Socket connection established, initiating session, client: /127.0.0.1:56077, server: 127.0.0.1/127.0.0.1:2181
2019-05-02 19:08:58.810  INFO 38709 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn          : Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x10006f79d980001, negotiated timeout = 40000
2019-05-02 19:08:58.810  INFO 38709 --- [ain-EventThread] o.a.c.f.state.ConnectionStateManager     : State change: RECONNECTED
2019-05-02 19:08:58.816  WARN 38709 --- [127.0.0.1:2181)] org.apache.zookeeper.ClientCnxn          : Session 0x10006f79d980001 for server 127.0.0.1/127.0.0.1:2181, unexpected error, closing socket connection and attempting reconnect

java.io.IOException: Xid out of order. Got Xid 21 with err -6 expected Xid 20 for a packet with details: clientPath:/app/test/app serverPath:/app/test/app finished:false header:: 20,12  replyHeader:: 0,0,-4  request:: '/app/test/app,F  response:: v{} 

Я что-то не так делаю.

1 Ответ

1 голос
/ 02 мая 2019

Похоже, что compile("org.apache.curator:curator-recipes:4.2.0") поставляется с org.apache.zookeeper:zookeeper:3.5.4-beta, чтобы он работал с Zookeeper 3.4.x, нам нужно следовать инструкциям из структуры куратора: https://curator.apache.org/zk-compatibility.html

Куратор 4.0 поддерживает ансамбли ZooKeeper 3.4.x в режиме программной совместимости. Чтобы использовать этот режим, вы должны исключить ZooKeeper при добавлении куратора в ваш инструмент управления зависимостями.

compile('org.springframework.integration:spring-integration-zookeeper') {
  exclude group: 'org.apache.zookeeper', module: 'zookeeper'
}

и, следовательно, включает zookeeper зависимость 3.4.14 версии.

Hm. И похоже, что вам также нужно исключить его из зависимости spring-cloud-zookeeper-core.

...