Skip to content

Commit

Permalink
Add specialized ProducerData classes for Kafka and AMQP
Browse files Browse the repository at this point in the history
  • Loading branch information
stavshamir committed Jun 6, 2022
1 parent 07c7690 commit 471ebdb
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ProducerData {
/**
* The name of the channel (topic, queue etc.).
*/
private String channelName;
protected String channelName;

/**
* The channel binding of the producer.
Expand All @@ -29,12 +29,12 @@ public class ProducerData {
* ImmutableMap.of("kafka", new KafkaChannelBinding())
* </code>
*/
private Map<String, ? extends ChannelBinding> channelBinding;
protected Map<String, ? extends ChannelBinding> channelBinding;

/**
* The class object of the payload published by this producer.
*/
private Class<?> payloadType;
protected Class<?> payloadType;

/**
* The operation binding of the producer.
Expand All @@ -44,6 +44,6 @@ public class ProducerData {
* ImmutableMap.of("kafka", new KafkaOperationBinding())
* </code>
*/
private Map<String, ? extends OperationBinding> operationBinding;
protected Map<String, ? extends OperationBinding> operationBinding;

}
2 changes: 1 addition & 1 deletion springwolf-examples/springwolf-amqp-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

sourceCompatibility = '1.8'
version '0.2.0'
version '0.3.0'

repositories {
// For local development with snapshots
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
app:
image: stavshamir/springwolf-amqp-example:0.2.0
image: stavshamir/springwolf-amqp-example:0.3.0
links:
- amqp
ports:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package io.github.stavshamir.springwolf.example.configuration;

import com.asyncapi.v2.binding.amqp.AMQPChannelBinding;
import com.asyncapi.v2.binding.amqp.AMQPOperationBinding;
import com.asyncapi.v2.model.info.Info;
import com.asyncapi.v2.model.server.Server;
import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.types.ProducerData;
import io.github.stavshamir.springwolf.asyncapi.types.AmqpProducerData;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
import io.github.stavshamir.springwolf.configuration.EnableAsyncApi;
import io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

@Configuration
@EnableAsyncApi
public class AsyncApiConfiguration {
Expand All @@ -41,18 +36,11 @@ public AsyncApiDocket asyncApiDocket() {
.url(String.format("%s:%s", amqpHost, amqpPort))
.build();

AMQPChannelBinding.ExchangeProperties exchangeProperties = new AMQPChannelBinding.ExchangeProperties();
exchangeProperties.setName("example-topic-exchange");
ProducerData exampleProducer = ProducerData.builder()
.channelName("example-producer-channel")
.channelBinding(ImmutableMap.of("amqp", AMQPChannelBinding.builder()
.is("routingKey")
.exchange(exchangeProperties)
.build()))
AmqpProducerData exampleProducer = AmqpProducerData.amqpProducerDataBuilder()
.queueName("example-producer-channel")
.exchangeName("example-topic-exchange")
.routingKey("example-topic-routing-key")
.payloadType(AnotherPayloadDto.class)
.operationBinding(ImmutableMap.of("amqp", AMQPOperationBinding.builder()
.cc(Collections.singletonList("example-topic-routing-key"))
.build()))
.build();

return AsyncApiDocket.builder()
Expand Down
2 changes: 1 addition & 1 deletion springwolf-examples/springwolf-kafka-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

sourceCompatibility = '1.8'
version '0.5.0'
version '0.6.0'


repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
app:
image: stavshamir/springwolf-kafka-example:0.5.0
image: stavshamir/springwolf-kafka-example:0.6.0
links:
- kafka
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.github.stavshamir.springwolf.example.configuration;

import com.asyncapi.v2.binding.kafka.KafkaOperationBinding;
import com.asyncapi.v2.model.info.Info;
import com.asyncapi.v2.model.server.Server;
import com.google.common.collect.ImmutableMap;
import io.github.stavshamir.springwolf.asyncapi.types.ProducerData;
import io.github.stavshamir.springwolf.asyncapi.types.KafkaProducerData;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
import io.github.stavshamir.springwolf.configuration.EnableAsyncApi;
import io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto;
Expand Down Expand Up @@ -32,8 +30,15 @@ public AsyncApiDocket asyncApiDocket() {
.title("Springwolf example project")
.build();

ProducerData exampleProducerData = buildKafkaProducerData(PRODUCER_TOPIC, ExamplePayloadDto.class);
ProducerData anotherProducerData = buildKafkaProducerData(PRODUCER_TOPIC, AnotherPayloadDto.class);
KafkaProducerData exampleProducerData = KafkaProducerData.kafkaProducerDataBuilder()
.topicName(PRODUCER_TOPIC)
.payloadType(ExamplePayloadDto.class)
.build();

KafkaProducerData anotherProducerData = KafkaProducerData.kafkaProducerDataBuilder()
.topicName(PRODUCER_TOPIC)
.payloadType(AnotherPayloadDto.class)
.build();

return AsyncApiDocket.builder()
.basePackage("io.github.stavshamir.springwolf.example.consumers")
Expand All @@ -44,12 +49,4 @@ public AsyncApiDocket asyncApiDocket() {
.build();
}

private ProducerData buildKafkaProducerData(String topic, Class<?> payload) {
return ProducerData.builder()
.channelName(topic)
.operationBinding(ImmutableMap.of("kafka", new KafkaOperationBinding()))
.payloadType(payload)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
},
"channels": {
"another-topic": {
"bindings": {
"kafka": {}
},
"publish": {
"bindings": {
"kafka": {
Expand All @@ -34,12 +31,12 @@
"$ref": "#/components/schemas/AnotherPayloadDto"
}
}
},
"bindings": {
"kafka": {}
}
},
"example-topic": {
"bindings": {
"kafka": {}
},
"publish": {
"bindings": {
"kafka": {}
Expand All @@ -51,13 +48,13 @@
"$ref": "#/components/schemas/ExamplePayloadDto"
}
}
}
},
"multi-payload-topic": {
},
"bindings": {
"kafka": {}
},
"publish": {
}
},
"example-producer-topic": {
"subscribe": {
"bindings": {
"kafka": {}
},
Expand All @@ -79,10 +76,13 @@
}
]
}
},
"bindings": {
"kafka": {}
}
},
"example-producer-topic": {
"subscribe": {
"multi-payload-topic": {
"publish": {
"bindings": {
"kafka": {}
},
Expand All @@ -104,6 +104,9 @@
}
]
}
},
"bindings": {
"kafka": {}
}
}
},
Expand Down Expand Up @@ -156,4 +159,4 @@
}
}
}
}
}
4 changes: 2 additions & 2 deletions springwolf-plugins/springwolf-amqp-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Add the following dependencies and configuration class to enable this plugin.
```groovy
dependencies {
// Provides the documentation API
implementation 'io.github.springwolf:springwolf-amqp:0.2.0'
implementation 'io.github.springwolf:springwolf-amqp:0.3.0'
// Provides the UI - optional (recommended)
runtimeOnly 'io.github.springwolf:springwolf-ui:0.3.1'
runtimeOnly 'io.github.springwolf:springwolf-ui:0.4.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion springwolf-plugins/springwolf-amqp-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'io.github.springwolf'
version '0.2.0'
version '0.3.0'
sourceCompatibility = 1.8

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.stavshamir.springwolf.asyncapi.types;

import com.asyncapi.v2.binding.amqp.AMQPChannelBinding;
import com.asyncapi.v2.binding.amqp.AMQPOperationBinding;
import com.google.common.collect.ImmutableMap;
import lombok.Builder;

import java.util.Collections;

public class AmqpProducerData extends ProducerData {

@Builder(builderMethodName = "amqpProducerDataBuilder")
public AmqpProducerData(String queueName, String exchangeName, String routingKey, Class<?> payloadType) {
this.channelName = queueName;

AMQPChannelBinding.ExchangeProperties exchangeProperties = new AMQPChannelBinding.ExchangeProperties();
exchangeProperties.setName(exchangeName);
this.channelBinding = ImmutableMap.of("amqp", AMQPChannelBinding.builder()
.is("routingKey")
.exchange(exchangeProperties)
.build());

this.operationBinding = ImmutableMap.of("amqp", AMQPOperationBinding.builder()
.cc(Collections.singletonList(routingKey))
.build());

this.payloadType = payloadType;
}

}
2 changes: 1 addition & 1 deletion springwolf-plugins/springwolf-kafka-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the following dependencies and configuration class to enable this plugin.
```groovy
dependencies {
// Provides the documentation API
implementation 'io.github.springwolf:springwolf-kafka:0.5.0'
implementation 'io.github.springwolf:springwolf-kafka:0.6.0'
// Provides the UI - optional (recommended)
runtimeOnly 'io.github.springwolf:springwolf-ui:0.4.0'
Expand Down
2 changes: 1 addition & 1 deletion springwolf-plugins/springwolf-kafka-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group 'io.github.springwolf'
version '0.5.0'
version '0.6.0'
sourceCompatibility = 1.8

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.stavshamir.springwolf.asyncapi.types;

import com.asyncapi.v2.binding.kafka.KafkaChannelBinding;
import com.asyncapi.v2.binding.kafka.KafkaOperationBinding;
import com.google.common.collect.ImmutableMap;
import lombok.Builder;

public class KafkaProducerData extends ProducerData {

@Builder(builderMethodName = "kafkaProducerDataBuilder")
public KafkaProducerData(String topicName, Class<?> payloadType) {
this.channelName = topicName;
this.channelBinding = ImmutableMap.of("kafka", new KafkaChannelBinding());
this.payloadType = payloadType;
this.operationBinding = ImmutableMap.of("kafka", new KafkaOperationBinding());
}

}

0 comments on commit 471ebdb

Please sign in to comment.