Skip to content

Commit 6f90400

Browse files
authored
Merge pull request #85 from zalando-nakadi/feature/#75-reuse-fahrschein-bean
Reuse Fahrschein bean if it already exists (#75).
2 parents a16d993 + e747f16 commit 6f90400

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ This library also uses:
5858
### Setup
5959

6060
If you are using maven, include the library in your `pom.xml`:
61+
6162
```xml
6263
<dependency>
6364
<groupId>org.zalando</groupId>
@@ -66,7 +67,10 @@ If you are using maven, include the library in your `pom.xml`:
6667
</dependency>
6768
```
6869

70+
The latest available version is visible in the Maven central badge at the top of this README.
71+
6972
Use `@EnableNakadiProducer` annotation to activate spring boot starter auto configuration:
73+
7074
```java
7175
@SpringBootApplication
7276
@EnableNakadiProducer
@@ -81,6 +85,22 @@ The library uses flyway migrations to set up its own database schema `nakadi_eve
8185

8286
### Nakadi communication configuration
8387

88+
By default, Nakadi-producer-spring-boot starter uses the Fahrschein library to submit its events. It needs some configuration to know how to do this – we support two ways:
89+
90+
* Using existing Fahrschein setup
91+
* Letting this library set things up
92+
93+
#### Using existing Fahrschein setup
94+
95+
If you are already using the [Fahrschein library](https://github.com/zalando-nakadi/fahrschein) directly (e.g. for event consumption) and have already a configured `org.zalando.fahrschein.NakadiClient` object, just make sure it is available as a Spring bean. Nakadi-Producer-Spring-Boot-Starter will pick it up and use it directly.
96+
97+
The configuration in the next section is then not needed at all.
98+
99+
#### Letting this library set things up
100+
101+
If you want Nakadi-Producer-Spring-Boot-Starter to configure the connection to Nakadi, you'll need to set some properties
102+
(and/or create beans).
103+
84104
You must tell the library, where it can reach your Nakadi instance:
85105
```yaml
86106
nakadi-producer:
@@ -116,6 +136,7 @@ nakadi-producer:
116136

117137
If you do not use the STUPS Tokens library, you can implement token retrieval yourself by defining a Spring bean of type `org.zalando.nakadiproducer.AccessTokenProvider`. The starter will detect it and call it once for each request to retrieve the token.
118138

139+
119140
### Creating events
120141

121142
The typical use case for this library is to publish events like creating or updating of some objects.

nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@
4949
@AutoConfigureAfter(name="org.zalando.tracer.spring.TracerAutoConfiguration")
5050
public class NakadiProducerAutoConfiguration {
5151

52-
@ConditionalOnMissingBean(NakadiPublishingClient.class)
52+
@ConditionalOnMissingBean({NakadiPublishingClient.class, NakadiClient.class})
5353
@Configuration
54-
@Import(FahrscheinNakadiClientConfiguration.StupsTokenConfiguration.class)
55-
static class FahrscheinNakadiClientConfiguration {
54+
@Import(FahrscheinWithTokensNakadiClientConfiguration.StupsTokenConfiguration.class)
55+
static class FahrscheinWithTokensNakadiClientConfiguration {
5656

5757
@Bean
5858
public NakadiPublishingClient nakadiProducerPublishingClient(AccessTokenProvider accessTokenProvider,
@@ -75,6 +75,17 @@ public StupsTokenComponent accessTokenProvider(
7575
}
7676
}
7777

78+
@ConditionalOnMissingBean(NakadiPublishingClient.class)
79+
@ConditionalOnBean(NakadiClient.class)
80+
@Configuration
81+
static class ExistingFahrscheinNakadiClientConfiguration {
82+
83+
@Bean
84+
public NakadiPublishingClient nakadiProducerPublishingClient(NakadiClient fahrscheinNakadiClient) {
85+
return new FahrscheinNakadiPublishingClient(fahrscheinNakadiClient);
86+
}
87+
}
88+
7889
@Bean
7990
@ConditionalOnMissingClass("org.zalando.tracer.Tracer")
8091
@ConditionalOnMissingBean(FlowIdComponent.class)

0 commit comments

Comments
 (0)