Skip to content
Snippets Groups Projects
Commit d770dccd authored by OZGCloud's avatar OZGCloud
Browse files

implement autostarter to configure grpc-client

parent 3d19040b
No related branches found
No related tags found
No related merge requests found
Showing
with 49 additions and 6 deletions
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
<!--spring --> <!--spring -->
<dependency> <dependency>
<groupId>net.devh</groupId> <groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId> <artifactId>grpc-client-spring-boot-autoconfigure</artifactId>
<version>2.14.0.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -5,9 +5,11 @@ import java.util.List; ...@@ -5,9 +5,11 @@ import java.util.List;
import lombok.Builder; import lombok.Builder;
import lombok.Getter; import lombok.Getter;
import lombok.Singular; import lombok.Singular;
import lombok.ToString;
@Builder @Builder
@Getter @Getter
@ToString
public class OzgCloudVorgang { public class OzgCloudVorgang {
private OzgCloudVorgangId id; private OzgCloudVorgangId id;
......
...@@ -6,6 +6,7 @@ import java.util.List; ...@@ -6,6 +6,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.ozgcloud.apilib.errorhandling.NotFoundException; import de.ozgcloud.apilib.errorhandling.NotFoundException;
...@@ -18,6 +19,7 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangStub; ...@@ -18,6 +19,7 @@ import de.ozgcloud.apilib.vorgang.OzgCloudVorgangStub;
import de.ozgcloud.apilib.vorgang.VorgangStatus; import de.ozgcloud.apilib.vorgang.VorgangStatus;
@Service @Service
@ConditionalOnMissingBean(OzgCloudVorgangService.class)
class DummyVorgangService implements OzgCloudVorgangService { class DummyVorgangService implements OzgCloudVorgangService {
private final Map<OzgCloudVorgangId, OzgCloudVorgang> idToVorgang; private final Map<OzgCloudVorgangId, OzgCloudVorgang> idToVorgang;
......
...@@ -2,6 +2,7 @@ package de.ozgcloud.apilib.vorgang.grpc; ...@@ -2,6 +2,7 @@ package de.ozgcloud.apilib.vorgang.grpc;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import de.itvsh.ozg.pluto.vorgang.GrpcFindVorgangWithEingangRequest; import de.itvsh.ozg.pluto.vorgang.GrpcFindVorgangWithEingangRequest;
...@@ -18,7 +19,7 @@ class GrpcVorgangService implements OzgCloudVorgangService { ...@@ -18,7 +19,7 @@ class GrpcVorgangService implements OzgCloudVorgangService {
@GrpcClient("vorgang-manager") @GrpcClient("vorgang-manager")
private VorgangServiceBlockingStub vorgangServiceStub; private VorgangServiceBlockingStub vorgangServiceStub;
@Autowired
private OzgCloudVorgangMapper mapper; private OzgCloudVorgangMapper mapper;
@Override @Override
......
...@@ -5,6 +5,7 @@ import org.springframework.context.ApplicationListener; ...@@ -5,6 +5,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangId;
import de.ozgcloud.apilib.vorgang.OzgCloudVorgangService; import de.ozgcloud.apilib.vorgang.OzgCloudVorgangService;
@Component @Component
...@@ -15,7 +16,7 @@ class DemoRunner implements ApplicationListener<ContextRefreshedEvent> { ...@@ -15,7 +16,7 @@ class DemoRunner implements ApplicationListener<ContextRefreshedEvent> {
@Override @Override
public void onApplicationEvent(ContextRefreshedEvent event) { public void onApplicationEvent(ContextRefreshedEvent event) {
System.out.println(vorgangService.search("test")); System.out.println(vorgangService.getById(OzgCloudVorgangId.from("647885a50b105b1e4995378e")));
} }
} }
ozgcloud:
vorgang-manager:
url: static://127.0.0.1:9090
\ No newline at end of file
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId> <artifactId>spring-boot-autoconfigure</artifactId>
</dependency> </dependency>
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
</dependency>
<dependency> <dependency>
<groupId>de.ozgcloud.api-lib</groupId> <groupId>de.ozgcloud.api-lib</groupId>
......
package de.ozgcloud.client.autoconfigure; package de.ozgcloud.client.autoconfigure;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration;
import net.devh.boot.grpc.client.config.GrpcChannelProperties;
import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
import net.devh.boot.grpc.client.config.NegotiationType;
@AutoConfiguration @AutoConfiguration
@ComponentScan(basePackages = "de.ozgcloud.apilib.**") @ComponentScan(basePackages = "de.ozgcloud.apilib.**")
@AutoConfigureBefore(GrpcClientAutoConfiguration.class)
//TODO remove component scan
public class OzgCloudClientAutoConfiguration { public class OzgCloudClientAutoConfiguration {
@Bean
GrpcChannelsProperties channelProperties() {
var properties = new GrpcChannelsProperties();
var channelProps = new GrpcChannelProperties();
properties.getClient().put("vorgang-manager", channelProps);
channelProps.setAddress("static://127.0.0.1:9090");
channelProps.setNegotiationType(NegotiationType.PLAINTEXT);
return properties;
}
} }
de.ozgcloud.client.autoconfigure.OzgCloudClientAutoConfiguration de.ozgcloud.client.autoconfigure.OzgCloudClientAutoConfiguration
net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration
\ No newline at end of file
grpc:
client:
vorgang-manager:
# address: ${ozgcloud.vorgang-manager.url}
address: static://127.0.0.1:9090
negotiationType: PLAINTEXT
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment