Skip to content

Commit

Permalink
Update Spring Pulsar for Boot 3.2.x
Browse files Browse the repository at this point in the history
* Split the Pulsar dependencies into Boot30/31 and
  Boot32 variants
* Add DockerCompose and Testcontainers support
* Enhance the tests for Pulsar
  • Loading branch information
onobc committed Sep 8, 2023
1 parent 8387b2d commit df1b966
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public SimpleDockerServiceResolver() {
this.dockerServices.put("mysql", mysql());
this.dockerServices.put("oracle", oracle());
this.dockerServices.put("postgres", postgres());
this.dockerServices.put("pulsar", pulsar());
this.dockerServices.put("rabbit", rabbit());
this.dockerServices.put("redis", redis());
this.dockerServices.put("sqlServer", sqlServer());
Expand Down Expand Up @@ -103,6 +104,15 @@ private static DockerService postgres() {
.build();
}

private static DockerService pulsar() {
// The latest tag they provide is not the 'latest' GA
return DockerService.withImageAndTag("apachepulsar/pulsar:3.1.0")
.website("https://hub.docker.com/r/apachepulsar/pulsar")
.command("bin/pulsar standalone")
.ports(8080, 6650)
.build();
}

private static DockerService rabbit() {
return DockerService.withImageAndTag("rabbitmq")
.website("https://hub.docker.com/_/rabbitmq")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,67 @@

package io.spring.start.site.extension.dependency.springpulsar;

import io.spring.initializr.generator.condition.ConditionalOnPlatformVersion;
import io.spring.initializr.generator.condition.ConditionalOnRequestedDependency;
import io.spring.initializr.generator.condition.ProjectGenerationCondition;
import io.spring.initializr.generator.project.ProjectDescription;
import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.start.site.container.ComposeFileCustomizer;
import io.spring.start.site.container.DockerServiceResolver;
import io.spring.start.site.container.ServiceConnections;
import io.spring.start.site.container.ServiceConnectionsCustomizer;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
* Configuration for generation of projects that depend on Pulsar.
*
* @author Chris Bono
*/
@ProjectGenerationConfiguration
@ConditionalOnRequestedDependency("pulsar")
@Conditional(SpringPulsarProjectGenerationConfiguration.OnPulsarRequestedDependencyCondition.class)
class SpringPulsarProjectGenerationConfiguration {

private static final String TESTCONTAINERS_CLASS_NAME = "org.testcontainers.containers.PulsarContainer";

@Bean
@ConditionalOnPlatformVersion("3.2.0-SNAPSHOT")
@ConditionalOnRequestedDependency("testcontainers")
ServiceConnectionsCustomizer pulsarServiceConnectionsCustomizer(DockerServiceResolver serviceResolver) {
return (serviceConnections) -> serviceResolver.doWith("pulsar",
(service) -> serviceConnections.addServiceConnection(ServiceConnections.ServiceConnection
.ofContainer("pulsar", service, TESTCONTAINERS_CLASS_NAME, false)));
}

@Bean
@ConditionalOnPlatformVersion("3.2.0-SNAPSHOT")
@ConditionalOnRequestedDependency("docker-compose")
ComposeFileCustomizer pulsarComposeFileCustomizer(DockerServiceResolver serviceResolver) {
return (composeFile) -> serviceResolver.doWith("pulsar",
(service) -> composeFile.services().add("pulsar", service));
}

@Bean
@ConditionalOnPlatformVersion("[3.0.0,3.2.0-M1)")
@ConditionalOnRequestedDependency("cloud-stream")
SpringPulsarBinderBuildCustomizer pulsarBinderBuildCustomizer(InitializrMetadata metadata,
ProjectDescription description) {
return new SpringPulsarBinderBuildCustomizer(metadata, description);
}

static class OnPulsarRequestedDependencyCondition extends ProjectGenerationCondition {

@Override
protected boolean matches(ProjectDescription description, ConditionContext context,
AnnotatedTypeMetadata metadata) {
return description.getRequestedDependencies().containsKey("pulsar")
|| description.getRequestedDependencies().containsKey("pulsar-reactive");
}

}

}
28 changes: 15 additions & 13 deletions start-site/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -788,30 +788,32 @@ initializr:
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#messaging.jms.artemis
- name: Spring for Apache Pulsar
id: pulsar
compatibilityRange: "[3.0.0,3.2.0-M1)"
mappings:
- compatibilityRange: "[3.0.0,3.2.0-M1)"
version: 0.2.0
compatibilityRange: "[3.0.0,3.2.0-SNAPSHOT]"
description: Build messaging applications with Apache Pulsar
groupId: org.springframework.pulsar
artifactId: spring-pulsar-spring-boot-starter
links:
- rel: reference
href: https://docs.spring.io/spring-pulsar/docs/0.2.x/reference/html/
- name: Spring for Apache Pulsar (Reactive)
id: pulsar-reactive
compatibilityRange: "[3.0.0,3.2.0-M1)"
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#messaging.pulsar
mappings:
- compatibilityRange: "[3.0.0,3.2.0-M1)"
version: 0.2.0
groupId: org.springframework.pulsar
artifactId: spring-pulsar-spring-boot-starter
starter: false
- name: Spring for Apache Pulsar (Reactive)
id: pulsar-reactive
compatibilityRange: "[3.0.0,3.2.0-SNAPSHOT]"
description: Build reactive messaging applications with Apache Pulsar
facets:
- reactive
groupId: org.springframework.pulsar
artifactId: spring-pulsar-reactive-spring-boot-starter
links:
- rel: reference
href: https://docs.spring.io/spring-pulsar/docs/0.2.x/reference/html/#reactive-pulsar
href: https://docs.spring.io/spring-boot/docs/{bootVersion}/reference/htmlsingle/index.html#messaging.pulsar
mappings:
- compatibilityRange: "[3.0.0,3.2.0-M1)"
version: 0.2.0
groupId: org.springframework.pulsar
artifactId: spring-pulsar-reactive-spring-boot-starter
starter: false
- name: WebSocket
id: websocket
description: Build Servlet-based WebSocket applications with SockJS and STOMP.
Expand Down

This file was deleted.

Loading

0 comments on commit df1b966

Please sign in to comment.