Skip to content

Commit 070698e

Browse files
committed
Reuse Fahrschein bean if it already exists (#75).
Also document how to not use Fahrschein at all.
1 parent a16d993 commit 070698e

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

README.md

Lines changed: 41 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,23 @@ 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 describe three ways here (basically in order of ease of use):
89+
90+
* Using existing Fahrschein setup
91+
* Letting this library set things up
92+
* Implement Nakadi communication yourself
93+
94+
#### Using existing Fahrschein setup
95+
96+
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.
97+
98+
The configurations in the next section are then not needed at all.
99+
100+
#### Letting this library set things up
101+
102+
If you want Nakadi-Producer-Spring-Boot-Starter to configure the connection to Nakadi, you'll need to set some properties
103+
(and/or create beans).
104+
84105
You must tell the library, where it can reach your Nakadi instance:
85106
```yaml
86107
nakadi-producer:
@@ -116,6 +137,26 @@ nakadi-producer:
116137

117138
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.
118139

140+
#### Implement Nakadi communication yourself
141+
142+
If you don't like Fahrschein, you can implement the communication with Nakadi yourself. Just provide an implementation of the `NakadiPublishingClient` interface as a Spring bean. Nakadi-producer-spring-boot-starter will just use that bean. (This is used in the [test support](#test-support) described below.)
143+
144+
You can then also exclude the Fahrschein dependency:
145+
146+
```xml
147+
<dependency>
148+
<groupId>org.zalando</groupId>
149+
<artifactId>nakadi-producer-spring-boot-starter</artifactId>
150+
<version>${nakadi-producer.version}</version>
151+
<exclusions>
152+
<exclusion>
153+
<groupId>org.zalando</groupId>
154+
<artifactId>fahrschein</artifactId>
155+
<exclusion>
156+
</exclusions>
157+
</dependency>
158+
```
159+
119160
### Creating events
120161

121162
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)