Skip to content

Commit

Permalink
Merge pull request #34 from ZenWave360/develop
Browse files Browse the repository at this point in the history
Release 1.6.1
  • Loading branch information
ivangsa authored Jul 18, 2024
2 parents a1ad274 + 4578066 commit 8860e7e
Show file tree
Hide file tree
Showing 55 changed files with 485 additions and 195 deletions.
26 changes: 13 additions & 13 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ body:
label: ZenWave Plugin
description: Which ZenWave plugin are you using?
options:
- "BackendApplicationDefaultPlugin: Generates a full backend application using a flexible hexagonal architecture"
- "ZDLToOpenAPIPlugin: Generates a draft OpenAPI definitions from your ZDL entities and services."
- "ZDLToAsyncAPIPlugin: Generates a draft AsyncAPI file with events from your ZDL services."
- "OpenAPIControllersPlugin: Generates implementations based on ZDL models and OpenAPI definitions SpringMVC generated OpenAPI interfaces."
- "SpringWebTestClientPlugin: Generates test for SpringMVC or Spring WebFlux using WebTestClient based on OpenAPI specification."
- "AsyncApiJsonSchema2PojoPlugin: Generate Plain Old Java Objects from OpenAPI/AsyncAPI schemas or full JSON-Schema files"
- "SpringCloudStreams3Plugin: Generates strongly typed SpringCloudStreams3 producer/consumer classes for AsyncAPI"
- "SpringCloudStreams3AdaptersPlugin: Generates tests for Spring Cloud Streams Consumers."
- "ZdlToMarkdownPlugin: Generates Markdown glossary from Zdl Models"
- "JDLToAsyncAPIPlugin: Generates a full AsyncAPI definitions for CRUD operations from JDL models"
- "OpenAPIToJDLPlugin: Generates JDL model from OpenAPI schemas"
- "ZdlToJsonPlugin: Prints to StdOut ZDL Model as JSON"
- "ForkPlugin: Creates a new standalone maven module cloning an existing plugin"
- BackendApplicationDefaultPlugin
- ZDLToOpenAPIPlugin
- ZDLToAsyncAPIPlugin
- OpenAPIControllersPlugin
- SpringWebTestClientPlugin
- AsyncApiJsonSchema2PojoPlugin
- SpringCloudStreams3Plugin
- SpringCloudStreams3AdaptersPlugin
- ZdlToMarkdownPlugin
- JDLToAsyncAPIPlugin
- OpenAPIToJDLPlugin
- ZdlToJsonPlugin
- ForkPlugin
validations:
required: true
- type: textarea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
<spring-boot.version>${project.parent.version}</spring-boot.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>

<zenwave.version>1.4.0-SNAPSHOT</zenwave.version>
<zenwave.version>1.6.0</zenwave.version>

<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
<archunit-junit5.version>1.0.1</archunit-junit5.version>
<spring-cloud-stream-schema.version>2.2.1.RELEASE</spring-cloud-stream-schema.version>
<hypersistence-utils-hibernate-63.version>3.7.3</hypersistence-utils-hibernate-63.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -96,11 +95,6 @@
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>io.hypersistence</groupId>
<artifactId>hypersistence-utils-hibernate-63</artifactId>
<version>${hypersistence-utils-hibernate-63.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<spring-boot.version>${project.parent.version}</spring-boot.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>

<zenwave.version>1.4.0-SNAPSHOT</zenwave.version>
<zenwave.version>1.6.0</zenwave.version>

<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<spring-cloud.version>2022.0.4</spring-cloud.version>
<spring-modulith-bom.version>1.1.1</spring-modulith-bom.version>

<zenwave.version>1.4.0-SNAPSHOT</zenwave.version>
<zenwave.version>1.6.0</zenwave.version>

<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<spring-boot.version>${project.parent.version}</spring-boot.version>
<spring-cloud.version>2022.0.4</spring-cloud.version>

<zenwave.version>1.4.0-SNAPSHOT</zenwave.version>
<zenwave.version>1.6.0</zenwave.version>

<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<mapstruct.version>1.5.3.Final</mapstruct.version>
Expand Down
12 changes: 5 additions & 7 deletions plugins/asyncapi-spring-cloud-streams3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ jbang zw -p io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin --help
| `transactionalOutbox` | Transactional outbox type for message producers. | TransactionalOutboxType | none | none, mongodb, jdbc |
| `useEnterpriseEnvelope` | Include support for enterprise envelop wrapping/unwrapping. | boolean | false | |
| `runtimeHeadersProperty` | AsyncAPI extension property name for runtime auto-configuration of headers. | String | x-runtime-expression | |
| `tracingIdSupplierQualifier` | Spring bean id for the tracing id supplier for runtime header with expression: '$tracingIdSupplier' | String | tracingIdSupplier | |
| `envelopeJavaTypeExtensionName` | AsyncAPI Message extension name for the envelop java type for wrapping/unwrapping. | String | x-envelope-java-type | |
| `includeKafkaCommonHeaders` | Include Kafka common headers 'kafka_messageKey' as x-runtime-header | boolean | false | |
| `consumerPrefix` | SC Streams Binder class prefix | String | | |
Expand All @@ -111,7 +110,7 @@ jbang zw -p io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin --help
ZenWave SDK provides `x-runtime-expression` for automatic header population at runtime. Values for this extension property are:

- `$message.payload#/<json pointer fragment>`: follows the same format as AsyncAPI [Correlation ID](https://www.asyncapi.com/docs/reference/specification/v2.5.0#correlationIdObject) object.
- `$tracingIdSupplier`: will use the tracing id `java.function.Supplier` configured in your Spring context.
- `$supplierBeanName`: will use a bean named `supplierBeanName` (you can use any other name) of type `java.function.Supplier` configured in your Spring context.

```yaml
CustomerEventMessage:
Expand All @@ -127,20 +126,19 @@ ZenWave SDK provides `x-runtime-expression` for automatic header population at r
tracingId:
type: string
description: This one will be populated automatically at runtime
x-runtime-expression: $tracingIdSupplier
x-runtime-expression: $supplierBeanName
```
```xml
<configOption>
<tracingIdSupplierQualifier>myTracingIdSupplier</tracingIdSupplierQualifier><!-- default is "tracingIdSupplier" -->
<runtimeHeadersProperty>x-custom-runtime-expression</runtimeHeadersProperty><!-- you can also override this extension property name -->
</configOption>
```

```java
@Bean("myTracingIdSupplier")
public Supplier tracingIdSupplier() {
return () -> "test-tracing-id";
@Bean("supplierBeanName")
public Supplier supplierBeanName() {
return () -> "some-value";
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public enum TransactionalOutboxType {
@DocumentedOption(description = "AsyncAPI extension property name for runtime auto-configuration of headers.")
public String runtimeHeadersProperty = "x-runtime-expression";

@DocumentedOption(description = "Spring bean id for the tracing id supplier for runtime header with expression: '$tracingIdSupplier'")
public String tracingIdSupplierQualifier = "tracingIdSupplier";

@DocumentedOption(description = "Include Kafka common headers 'kafka_messageKey' as x-runtime-header")
private boolean includeKafkaCommonHeaders = false;

Expand Down Expand Up @@ -141,6 +138,33 @@ public enum TransactionalOutboxType {
}
return runtimeHeaders.stream().collect(Collectors.joining(", "));
});
handlebarsEngine.getHandlebars().registerHelper("propertyType", (context, options) -> {
Map property = (Map) context;
String type = (String) property.get("type");
String format = (String) property.get("format");
if ("date".equals(format)) {
return "LocalDate";
}
if ("date-time".equals(format)) {
return "Instant";
}
if ("integer".equals(type) && "int32".equals(format)) {
return "Integer";
}
if ("integer".equals(type) && "int64".equals(format)) {
return "Long";
}
if ("number".equals(type)) {
return "BigDecimal";
}
if ("boolean".equals(type)) {
return "Boolean";
}
if("string".equals(type)) {
return "String";
}
return "Object";
});
}

protected String templatesPath = "io/zenwave360/sdk/plugins/SpringCloudStream3Generator";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
/** {{{header.description}}} */
{{~/if}}
{{~#if isProducer}}
public {{message.x--javaTypeSimpleName}}Headers {{asInstanceName @key}}(String {{asInstanceName @key}}) {
public {{message.x--javaTypeSimpleName}}Headers {{asInstanceName @key}}({{propertyType header}} {{asInstanceName @key}}) {
return set("{{@key}}", {{asInstanceName @key}});
}
{{~else}}
public String {{asInstanceName @key}}() {
return (String) get("{{@key}}");
public {{propertyType header}} {{asInstanceName @key}}() {
return ({{propertyType header}}) get("{{@key}}");
}
{{~/if}}
{{~/each}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
Expand All @@ -23,12 +24,16 @@ public class {{apiClassName serviceName operationRoleType}}Captor implements I{{

protected Logger log = LoggerFactory.getLogger(getClass());

protected ApplicationContext applicationContext;
public {{apiClassName serviceName operationRoleType}}Captor withApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
return this;
}

{{~#each operations as |operation|}}
public String {{operation.operationId}}BindingName = "{{bindingPrefix}}{{operation.x--operationIdKebabCase}}-out{{bindingSuffix}}";
{{~/each}}

{{> (partial '../partials/tracing-id-supplier')}}

{{~#if useEnterpriseEnvelope}}
public EnvelopeWrapper envelopeWrapper;
public void setEnvelopeWrapper(EnvelopeWrapper envelopeWrapper) {
Expand Down Expand Up @@ -63,7 +68,7 @@ public class {{apiClassName serviceName operationRoleType}}Captor implements I{{
headers = headers != null ? headers : new {{message.x--javaTypeSimpleName}}Headers();
processRuntimeHeaders(payload, headers, {{message.x--javaTypeSimpleName}}Headers._runtimeheaders);
{{~/if}}
Message message = MessageBuilder.createMessage({{#if (hasEnterpriseEnvelope operation)}}wrap(payload){{else}}payload{{/if}}, new MessageHeaders(headers));
Message message = MessageBuilder.createMessage({{#if (hasEnterpriseEnvelope operation)}}wrap(wrapNullPayload(payload)){{else}}wrapNullPayload(payload){{/if}}, new MessageHeaders(headers));
return appendCapturedMessage({{operation.operationId}}BindingName, message);
}

Expand All @@ -83,5 +88,6 @@ public class {{apiClassName serviceName operationRoleType}}Captor implements I{{
}
{{/if~}}

{{> (partial '../partials/wrapNullPayload') }}
{{> (partial '../partials/runtime-headers') }}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
Expand Down Expand Up @@ -35,14 +36,14 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
public String {{operation.operationId}}OutboxTableName = "{{snakeCase operation.operationId}}_outbox";
{{~/each}}

protected StreamBridge streamBridge;
protected final StreamBridge streamBridge;
protected final ApplicationContext applicationContext;
protected JdbcTemplate jdbcTemplate;
protected ObjectMapper objectMapper = new ObjectMapper();

{{> (partial '../../partials/tracing-id-supplier')}}

public {{apiClassName serviceName operationRoleType}}(StreamBridge streamBridge, JdbcTemplate jdbcTemplate) {
public {{apiClassName serviceName operationRoleType}}(StreamBridge streamBridge, ApplicationContext applicationContext, JdbcTemplate jdbcTemplate) {
this.streamBridge = streamBridge;
this.applicationContext = applicationContext;
this.jdbcTemplate = jdbcTemplate;
}

Expand All @@ -53,7 +54,7 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
var type = (String) outboxTableRow.get("type");
var payload = fromColumnData(outboxTableRow.get("payload"), type);
var headers = fromHeadersColumn((String) outboxTableRow.get("headers"));
Message message = MessageBuilder.createMessage(payload, new MessageHeaders(headers));
Message message = MessageBuilder.createMessage(wrapNullPayload(payload), new MessageHeaders(headers));
streamBridge.send(bindingName, message);
}

Expand All @@ -75,7 +76,7 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
headers = headers != null ? headers : new {{message.x--javaTypeSimpleName}}Headers();
processRuntimeHeaders(payload, headers, {{message.x--javaTypeSimpleName}}Headers._runtimeheaders);
{{~/if}}
Message message = MessageBuilder.createMessage(payload, new MessageHeaders(headers));
Message message = MessageBuilder.createMessage(wrapNullPayload(payload), new MessageHeaders(headers));
//return streamBridge.send({{operation.operationId}}BindingName, message);
return saveMessageToOutbox(message, {{operation.operationId}}OutboxTableName, {{operation.operationId}}BindingName);
}
Expand Down Expand Up @@ -118,6 +119,7 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
abstract void getSchema();
}

{{> (partial '../../partials/wrapNullPayload')}}
{{> (partial '../../partials/runtime-headers')}}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.ApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.messaging.MessageListener;
import org.springframework.data.mongodb.core.query.Criteria;
Expand Down Expand Up @@ -40,17 +41,17 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
public String {{operation.operationId}}OutboxCollection = {{operation.operationId}}BindingName;
{{~/each}}

protected StreamBridge streamBridge;
protected final StreamBridge streamBridge;
protected final ApplicationContext applicationContext;
protected MongoTemplate mongoTemplate;

public String resumeTokensCollectionName = "ChangeStreamResumeTokens";
public int skipMessagesBeforePersistingResumeToken = 100;
private Map<String, Integer> messageCounters = new HashMap();

{{> (partial '../../partials/tracing-id-supplier')}}

public {{apiClassName serviceName operationRoleType}}(StreamBridge streamBridge, MongoTemplate mongoTemplate) {
public {{apiClassName serviceName operationRoleType}}(StreamBridge streamBridge, ApplicationContext applicationContext, MongoTemplate mongoTemplate) {
this.streamBridge = streamBridge;
this.applicationContext = applicationContext;
this.mongoTemplate = mongoTemplate;
}

Expand All @@ -74,7 +75,7 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
public void sendOutboxMessage(org.springframework.data.mongodb.core.messaging.Message<ChangeStreamDocument<Document>, Map> outboxMessage, String collectionName, String eventBindingName) {
log.debug("Sending outbox message to stream {}", eventBindingName);
// send message to the stream
Message message = MessageBuilder.createMessage(outboxMessage.getBody().get("payload"), new MessageHeaders((Map<String, Object>) outboxMessage.getBody().get("headers")));
Message message = MessageBuilder.createMessage(wrapNullPayload(outboxMessage.getBody().get("payload")), new MessageHeaders((Map<String, Object>) outboxMessage.getBody().get("headers")));
streamBridge.send(eventBindingName, message);

// persist resume token
Expand Down Expand Up @@ -111,14 +112,15 @@ public class {{apiClassName serviceName operationRoleType}} implements I{{apiCla
headers = headers != null ? headers : new {{message.x--javaTypeSimpleName}}Headers();
processRuntimeHeaders(payload, headers, {{message.x--javaTypeSimpleName}}Headers._runtimeheaders);
{{~/if}}
Message message = MessageBuilder.createMessage(payload, new MessageHeaders(headers));
Message message = MessageBuilder.createMessage(wrapNullPayload(payload), new MessageHeaders(headers));
// return streamBridge.send({{operation.operationId}}BindingName, message, outputContentType);
return saveMessageToOutbox(message, {{operation.operationId}}OutboxCollection);
}

{{~/each}}
{{~/each}}

{{> (partial '../../partials/wrapNullPayload')}}
{{> (partial '../../partials/runtime-headers')}}

}
Loading

0 comments on commit 8860e7e

Please sign in to comment.