├── pulsar-spring-cloud-stream-binder
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── META-INF
│ │ │ │ ├── spring.binders
│ │ │ │ └── spring.factories
│ │ └── java
│ │ │ └── com
│ │ │ └── datastax
│ │ │ └── oss
│ │ │ └── pulsar
│ │ │ └── springcloudstream
│ │ │ ├── config
│ │ │ ├── PulsarClientAutoConfiguration.java
│ │ │ ├── PulsarClientConfigurationProperties.java
│ │ │ └── PulsarBinderConfiguration.java
│ │ │ ├── properties
│ │ │ ├── SchemaSpec.java
│ │ │ ├── PulsarBinderConfigurationProperties.java
│ │ │ ├── PulsarProducerProperties.java
│ │ │ ├── PulsarBindingProperties.java
│ │ │ ├── PulsarConsumerProperties.java
│ │ │ └── PulsarExtendedBindingProperties.java
│ │ │ ├── provisioning
│ │ │ ├── PulsarConsumerDestination.java
│ │ │ ├── PulsarProducerDestination.java
│ │ │ └── PulsarTopicProvisioner.java
│ │ │ ├── PulsarConsumerEndpoint.java
│ │ │ ├── PulsarProducerMessageHandler.java
│ │ │ └── PulsarMessageChannelBinder.java
│ └── test
│ │ ├── resources
│ │ └── logback-test.xml
│ │ └── java
│ │ └── com
│ │ └── datastax
│ │ └── oss
│ │ └── pulsar
│ │ └── springcloudstream
│ │ ├── provisioning
│ │ └── PulsarTopicProvisionerTests.java
│ │ ├── PulsarContainerTest.java
│ │ ├── PulsarTestBinder.java
│ │ ├── PulsarBinderTests.java
│ │ └── PulsarBinderFunctionalTests.java
└── pom.xml
├── README.md
├── .gitignore
├── pom.xml
└── LICENSE
/pulsar-spring-cloud-stream-binder/src/main/resources/META-INF/spring.binders:
--------------------------------------------------------------------------------
1 | pulsar: com.datastax.oss.pulsar.springcloudstream.config.PulsarBinderConfiguration
2 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/resources/META-INF/spring.factories:
--------------------------------------------------------------------------------
1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.datastax.oss.pulsar.springcloudstream.config.PulsarClientAutoConfiguration
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # pulsar-spring-cloud-stream-binder
2 |
3 | Apache Pulsar [binder](https://github.com/spring-cloud/spring-cloud-stream/blob/main/docs/src/main/asciidoc/spring-cloud-stream.adoc#binders) for Spring Cloud Stream
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | apps/
2 | /application.yml
3 | /application.properties
4 | asciidoctor.css
5 | *~
6 | .#*
7 | *#
8 | target/
9 | build/
10 | bin/
11 | _site/
12 | .classpath
13 | .project
14 | .settings
15 | .springBeans
16 | .DS_Store
17 | *.sw*
18 | *.iml
19 | *.ipr
20 | *.iws
21 | .idea/
22 | .factorypath
23 | spring-xd-samples/*/xd
24 | dump.rdb
25 | coverage-error.log
26 | .apt_generated
27 | aws.credentials.properties
28 | nb-configuration.xml
29 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/test/java/com/datastax/oss/pulsar/springcloudstream/provisioning/PulsarTopicProvisionerTests.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.provisioning;
18 |
19 | /**
20 | * Tests for the {@link PulsarTopicProvisioner}.
21 | *
22 | * @author Lari Hotari
23 | */
24 | class PulsarTopicProvisionerTests {
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/config/PulsarClientAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.datastax.oss.pulsar.springcloudstream.config;
2 |
3 | import org.apache.pulsar.client.api.PulsarClient;
4 | import org.apache.pulsar.client.api.PulsarClientException;
5 | import org.apache.pulsar.client.impl.ClientBuilderImpl;
6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
7 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
8 | import org.springframework.context.annotation.Bean;
9 | import org.springframework.context.annotation.Configuration;
10 | import org.springframework.context.annotation.Lazy;
11 |
12 | @Configuration(proxyBeanMethods = false)
13 | @EnableConfigurationProperties(PulsarClientConfigurationProperties.class)
14 | public class PulsarClientAutoConfiguration {
15 | @Bean
16 | @Lazy
17 | @ConditionalOnMissingBean
18 | PulsarClient pulsarClient(
19 | PulsarClientConfigurationProperties pulsarClientConfigurationProperties)
20 | throws PulsarClientException {
21 | return new ClientBuilderImpl(pulsarClientConfigurationProperties).build();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/properties/SchemaSpec.java:
--------------------------------------------------------------------------------
1 | package com.datastax.oss.pulsar.springcloudstream.properties;
2 |
3 | import org.apache.pulsar.client.api.Schema;
4 | import org.apache.pulsar.common.schema.SchemaType;
5 |
6 | public class SchemaSpec {
7 | private SchemaType type = SchemaType.BYTES;
8 | private Class> valueClass = byte[].class;
9 |
10 | public SchemaType getType() {
11 | return type;
12 | }
13 |
14 | public void setType(SchemaType type) {
15 | this.type = type;
16 | switch (type) {
17 | case STRING:
18 | valueClass = String.class;
19 | break;
20 | case BYTES:
21 | valueClass = byte[].class;
22 | break;
23 | }
24 | }
25 |
26 | public Class> getValueClass() {
27 | return valueClass;
28 | }
29 |
30 | public void setValueClass(Class> valueClass) {
31 | this.valueClass = valueClass;
32 | }
33 |
34 | public Schema> asPulsarSchema() {
35 | switch (type) {
36 | case STRING:
37 | return Schema.STRING;
38 | case AVRO:
39 | return Schema.AVRO(valueClass);
40 | case JSON:
41 | return Schema.JSON(valueClass);
42 | }
43 |
44 | return Schema.BYTES;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/provisioning/PulsarConsumerDestination.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.provisioning;
18 |
19 | import org.springframework.cloud.stream.provisioning.ConsumerDestination;
20 |
21 | /**
22 | * The Pulsar-specific {@link ConsumerDestination} implementation.
23 | *
24 | * @author Lari Hotari
25 | *
26 | */
27 | public final class PulsarConsumerDestination implements ConsumerDestination {
28 |
29 | private final String topicName;
30 |
31 | public PulsarConsumerDestination(String topicName) {
32 | this.topicName = topicName;
33 | }
34 |
35 | @Override
36 | public String getName() {
37 | return this.topicName;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/properties/PulsarBinderConfigurationProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.properties;
18 |
19 | import org.springframework.boot.context.properties.ConfigurationProperties;
20 |
21 | /**
22 | * The Pulsar Binder specific configuration properties.
23 | *
24 | * @author Lari Hotari
25 | */
26 | @ConfigurationProperties(prefix = "pulsar.spring.cloud.stream.binder")
27 | public class PulsarBinderConfigurationProperties {
28 | private String[] headers = new String[] { };
29 |
30 | public String[] getHeaders() {
31 | return this.headers;
32 | }
33 |
34 | public void setHeaders(String... headers) {
35 | this.headers = headers;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/provisioning/PulsarProducerDestination.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.provisioning;
18 |
19 | import org.springframework.cloud.stream.provisioning.ProducerDestination;
20 |
21 | /**
22 | * The Pulsar-specific {@link ProducerDestination} implementation.
23 | *
24 | * @author Lari Hotari
25 | *
26 | */
27 | public final class PulsarProducerDestination implements ProducerDestination {
28 |
29 | private final String topicName;
30 |
31 | PulsarProducerDestination(String topicName) {
32 | this.topicName = topicName;
33 | }
34 |
35 | @Override
36 | public String getName() {
37 | return this.topicName;
38 | }
39 |
40 | @Override
41 | public String getNameForPartition(int partition) {
42 | return this.topicName + "-partition-" + partition;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/properties/PulsarProducerProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.properties;
18 |
19 | import org.apache.pulsar.client.impl.conf.ProducerConfigurationData;
20 |
21 | /**
22 | * The Pulsar-specific producer binding configuration properties.
23 | *
24 | * @author Lari Hotari
25 | *
26 | */
27 | public class PulsarProducerProperties extends ProducerConfigurationData {
28 | private boolean useSendAsync;
29 | private SchemaSpec schema = new SchemaSpec();
30 | public PulsarProducerProperties() {
31 | setBlockIfQueueFull(true);
32 | }
33 |
34 | public boolean isUseSendAsync() {
35 | return useSendAsync;
36 | }
37 |
38 | public void setUseSendAsync(boolean useSendAsync) {
39 | this.useSendAsync = useSendAsync;
40 | }
41 |
42 | public SchemaSpec getSchema() {
43 | return schema;
44 | }
45 |
46 | public void setSchema(SchemaSpec schema) {
47 | this.schema = schema;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/properties/PulsarBindingProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.properties;
18 |
19 | import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
20 |
21 | /**
22 | * The Pulsar-specific binding configuration properties.
23 | *
24 | * @author Lari Hotari
25 | */
26 | public class PulsarBindingProperties implements BinderSpecificPropertiesProvider {
27 |
28 | private PulsarConsumerProperties consumer = new PulsarConsumerProperties();
29 |
30 | private PulsarProducerProperties producer = new PulsarProducerProperties();
31 |
32 | public PulsarConsumerProperties getConsumer() {
33 | return this.consumer;
34 | }
35 |
36 | public void setConsumer(PulsarConsumerProperties consumer) {
37 | this.consumer = consumer;
38 | }
39 |
40 | public PulsarProducerProperties getProducer() {
41 | return this.producer;
42 | }
43 |
44 | public void setProducer(PulsarProducerProperties producer) {
45 | this.producer = producer;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/pulsar-spring-cloud-stream-binder/src/main/java/com/datastax/oss/pulsar/springcloudstream/properties/PulsarConsumerProperties.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.datastax.oss.pulsar.springcloudstream.properties;
18 |
19 | import org.apache.pulsar.client.api.SubscriptionInitialPosition;
20 | import org.apache.pulsar.client.api.SubscriptionType;
21 | import org.apache.pulsar.client.impl.conf.ConsumerConfigurationData;
22 |
23 | /**
24 | * The Pulsar-specific consumer binding configuration properties.
25 | *
26 | * @author Lari Hotari
27 | *
28 | */
29 | public class PulsarConsumerProperties extends ConsumerConfigurationData