Giriş
Açıklaması şöyle
@EnableDiscoveryClient which comes from spring-cloud-commons is the same as @EnableEurekaClient but it is a more generic implementation of “Discovery Service”.@EnableZookeeper Anotasyonu
@EnableEurekaClient only works with Eureka whereas @EnableDiscoveryClient works with eureka, consul, zookeeper. But if Eureka is on the application classpath, they are effectively the same.
Maven
Şu satırı dahil ederiz
<dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.5.7</version></dependency>
Örnek
Şöyle yaparız
@Configuration @EnableZookeeper public class ZooKeeperConfiguration extends ZookeeperProperties { public ZooKeeperConfiguration() { setConnectString("localhost:2181"); setBaseSleepTimeMs(1000); setMaxRetries(3); setSessionTimeoutMs(5000); } } @Service public class MyService { @Autowired private ZooKeeperClient zooKeeperClient; public List<String> getNodes(String path) throws KeeperException, InterruptedException { return zooKeeperClient.getChildren(path); } }
Açıklaması şöyle
Next, you’ll need to configure the connection to your ZooKeeper server. You can do this by creating a ZooKeeperConfiguration class that extends org.springframework.cloud.zookeeper.ZookeeperProperties and sets the connection properties, like so:This sets the connection string to localhost:2181 and configures some other properties for the connection.Finally, you can use the ZooKeeper client in your Spring Boot application by autowiring a ZooKeeperClient instance.
Hiç yorum yok:
Yorum Gönder