Running Stork Locally #635
-
Folks, please, i need some help! I want to use Stork in a standalone application, whitout Spring or Quarkus. For example, i want to use Consul as my Service Discovery. But i can´t find any documentation which can clarify to me how to do this. Which dependencies i need to declare in pom.xml? Where i need to put configuration? How Stork find the properties configuration, for example, stork.my-service.service-discovery.type=consul? In the following snippet public static void main(String[] args) { |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
It depends. |
Beta Was this translation helpful? Give feedback.
-
So, here is a complete example, using the static list discovery, but you can use any discovery/selection: First, the <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>stork-bare</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-core</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>io.smallrye.stork</groupId>
<artifactId>stork-service-discovery-static-list</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
</project> Then, the code: package me.escoffier.stork.demo;
import io.smallrye.stork.Stork;
import io.smallrye.stork.api.ServiceDefinition;
import io.smallrye.stork.servicediscovery.staticlist.StaticConfiguration;
public class Main {
public static void main(String[] args) {
Stork.initialize();
var stork = Stork.getInstance()
.defineIfAbsent("my-service", ServiceDefinition.of(new StaticConfiguration()
.withAddressList("localhost:9000, localhost:9001")
.withShuffle("true"))); // Using the round-robin, but you can also configure a load balancer too.
var svc = stork.getService("my-service");
for (int i = 0; i < 5; i++) {
var instance = svc.selectInstance().await().indefinitely();
System.out.printf("Selected instance is : %d, %s:%d%n", instance.getId(), instance.getHost(), instance.getPort());
}
}
} So, I don't understand how you went on the annotation processing path. |
Beta Was this translation helpful? Give feedback.
It depends.
If you are in a CDI environment, I recommend using a Microprofile config implementation (such as SmallRye Config). You must use the API to define your services if you are not in a CDI environment. See https://smallrye.io/smallrye-stork/2.3.2/programmatic-api/ for details.