This is an automated email from the ASF dual-hosted git repository.

xiangying pushed a commit to branch stable
in repository https://gitbox.apache.org/repos/asf/pulsar-java-contrib.git

commit c3fcd17feb448515ce4e2e28d62f119f30894b3f
Author: nuolin <lush...@xiaohongshu.com>
AuthorDate: Thu Jul 25 01:21:47 2024 +0800

    init project
---
 .github/workflows/gradle.yml                       |   2 +-
 README.adoc                                        | 134 ---------------------
 README.md                                          |  37 ++++++
 .../src/main/assembly/sources.xml                  |  11 ++
 pom.xml                                            |   4 +-
 pulsar-client-contrib/README.md                    |  37 ++++++
 pulsar-client-contrib/pom.xml                      |  25 ++++
 .../pulsar/client/api/MessageListenerExecutor.java |  45 +++++++
 .../api/impl/KeySharedMessageListenerExecutor.java |  31 +++++
 9 files changed, 189 insertions(+), 137 deletions(-)

diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index bfe2a31..5750974 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -39,7 +39,7 @@ jobs:
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        quickstartDir: ['hello-world', 'use-cases/school-timetabling', 
'technology/java-spring-boot']
+        quickstartDir: ['hello-world', 'pulsar-client-contrib', 
'use-cases/school-timetabling', 'technology/java-spring-boot']
         java-version: [17] # JDK 19 not yet supported by Gradle.
     steps:
       - uses: actions/checkout@v3
diff --git a/README.adoc b/README.adoc
deleted file mode 100644
index b1f9ead..0000000
--- a/README.adoc
+++ /dev/null
@@ -1,134 +0,0 @@
-= OptaPlanner Quickstarts
-
-== Overview of all Quickstarts
-
-|===
-|Use case quickstarts |Technology quickstarts
-
-a|* <<school-timetabling, School timetabling>>
-* <<facility-location, Facility location problem>>
-* <<maintenance-scheduling, Maintenance scheduling>>
-* <<call-center, Call center>>
-* <<vaccination-scheduling, Vaccination scheduling>>
-* <<order-picking, Order Picking>>
-* <<employee-scheduling, Employee Scheduling>>
-* <<vehicle-routing, Vehicle Routing>>
-
-a|* link:use-cases/school-timetabling/README.adoc[Quarkus] (Java, Maven or 
Gradle, Quarkus, H2)
-* link:technology/java-spring-boot/README.adoc[Spring Boot] (Java, Maven or 
Gradle, Spring Boot, H2)
-* link:technology/java-activemq-quarkus/README.adoc[ActiveMQ] (Java, ActiveMQ, 
Maven, Quarkus)
-* link:technology/kotlin-quarkus/README.adoc[Kotlin] (Kotlin, Maven, Quarkus, 
H2)
-* link:technology/python/README.adoc[Python (experimental)] (Python, Pip)
-
-2+a|* <<optaplanner-examples, OptaPlanner examples (desktop)>>
-|===
-
-== Get started
-
-Run the https://www.optaplanner.org/[OptaPlanner] quickstarts now:
-
-. https://adoptopenjdk.net[Install JDK 11 or later] with `JAVA_HOME` 
configured appropriately.
-
-. Clone this repository to build and run the quickstarts showcase:
-+
-[source, shell]
-----
-$ git clone https://github.com/kiegroup/optaplanner-quickstarts.git
-$ cd optaplanner-quickstarts
-$ ./runQuickstartsFromSource.sh
-----
-
-== Use cases
-
-[[school-timetabling]]
-=== School timetabling
-
-Assign lessons to timeslots and rooms to produce a better schedule for 
teachers and students.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-school-timetabling-screenshot.png[]
-
-* link:use-cases/school-timetabling/README.adoc[Run 
quarkus-school-timetabling] (Java, Maven or Gradle, Quarkus, H2)
-* link:technology/java-spring-boot/README.adoc[Run 
spring-boot-school-timetabling] (Java, Maven or Gradle, Spring Boot, H2)
-* link:technology/java-activemq-quarkus/README.adoc[Run 
activemq-quarkus-school-timetabling] (Java, ActiveMQ, Maven, Quarkus)
-* link:technology/kotlin-quarkus/README.adoc[Run 
kotlin-quarkus-school-timetabling] (Kotlin, Maven, Quarkus, H2)
-* link:use-cases/vehicle-routing/README.adoc[Run quarkus-vehicle-routing] 
(Java, Maven or Gradle, Quarkus)
-
-Without a UI:
-
-* link:hello-world/README.adoc[Run hello-world-school-timetabling] (Java, 
Maven or Gradle)
-
-[[facility-location]]
-=== Facility location problem
-
-Pick the best geographical locations for new stores, distribution centers, 
covid test centers or telco masts.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-facility-location-screenshot.png[]
-
-* link:use-cases/facility-location/README.adoc[Run quarkus-facility-location] 
(Java, Maven, Quarkus)
-
-[[maintenance-scheduling]]
-=== Maintenance scheduling
-
-Schedule maintenance jobs to crews over time to reduce both premature and 
overdue maintenance.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-maintenance-scheduling-screenshot.png[]
-
-* link:use-cases/maintenance-scheduling/README.adoc[Run 
quarkus-maintenance-scheduling] (Java, Maven, Quarkus)
-
-[[call-center]]
-=== Call center
-
-Schedule incoming calls to employees matching skills and availability.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-call-center-screenshot.png[]
-
-* link:use-cases/call-center/README.adoc[Run quarkus-call-center] (Java, 
Maven, Quarkus)
-
-[[vaccination-scheduling]]
-=== Vaccination scheduling
-
-Assign people to vaccination injection appointments over time at vaccination 
centers to end a pandemic sooner.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-vaccination-scheduling-screenshot.png[]
-
-* link:use-cases/vaccination-scheduling/README.adoc[Run 
quarkus-vaccination-scheduling] (Java, Maven, Quarkus)
-
-[[order-picking]]
-=== Order Picking
-
-Generate an optimal picking plan for completing a set of orders.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-order-picking-screenshot.png[]
-
-* link:use-cases/order-picking/README.adoc[Run quarkus-order-picking] (Java, 
Maven, Quarkus)
-
-[[employee-scheduling]]
-=== Employee Scheduling
-
-Schedule shifts to employees, accounting for employee availability and shift 
skill requirements.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-employee-scheduling-screenshot.png[]
-
-* link:use-cases/employee-scheduling/README.adoc[Run 
quarkus-employee-scheduling] (Java, Maven, Quarkus)
-
-[[vehicle-routing]]
-=== Vehicle Routing
-
-Find the most efficient routes for a fleet of vehicles.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/quarkus-vehicle-routing-screenshot.png[]
-
-* link:use-cases/vehicle-routing/README.adoc[Run quarkus-vehicle-routing] 
(Java, Maven, Quarkus)
-
-[[optaplanner-examples]]
-=== OptaPlanner examples (desktop)
-
-Many examples in desktop technology.
-
-image::build/quickstarts-showcase/src/main/resources/META-INF/resources/screenshot/optaplanner-examples-screenshot.png[]
-
-* https://www.optaplanner.org/download/download.html[Download]
-
-== More information
-
-Learn more on https://www.optaplanner.org/[www.optaplanner.org].
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b7ed14e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,37 @@
+# Apache Pulsar Java Contrib
+
+[![Build](https://github.com/StevenLuMT/pulsar-java-contrib/actions/workflows/build.yml/badge.svg)](https://github.com/StevenLuMT/pulsar-java-contrib/actions/workflows/build.yml)
+
+pulsar-java-contrib is similar to the positioning of 
[opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib):
 
+* One is to prevent the Pulsar main repository from adding too many 
unnecessary functions, which would make Pulsar too bloated, increasing the 
user's usage cost and our maintenance cost.
+* The other is to reduce the user's usage cost by implementing a ready-to-use 
implementation class based on Pulsar's external interface.
+
+these ways achieve these two goals are the plugin library and the yellow 
pages. If you need an easier way to implement some plugin library based on 
Pulsar that cannot be easily satisfied by importing Pulsar directly, then this 
project is hopefully for you.
+
+## Provided Libraries
+
+
+* [Pulsar Client Contrib](./pulsar-client-contrib/README.md)
+
+## Getting Started
+
+```bash
+
+```
+
+## Contributing
+
+pulsar-java-contrib is actively in development.  If you have an idea for a 
similar use case in the metrics, traces, or logging
+domain we would be very interested in supporting it.  Please
+[open an 
issue](https://github.com/StevenLuMT/pulsar-java-contrib/issues/new/choose) to 
share your idea or
+suggestion.  PRs are always welcome and greatly appreciated, but for larger 
functional changes a pre-coding introduction
+can be helpful to ensure this is the correct place and that active or 
conflicting efforts don't exist.
+
+Emeritus maintainers:
+- [Steven Lu](https://github.com/StevenLuMT)
+- [Liangyepian Zhou](https://github.com/liangyepianzhou)
+- [Linlin Duan](https://github.com/AuroraTwinkle)
+- [Fenggan Cai](https://github.com/cai152)
+- [Jia Zhai](https://github.com/jiazhai)
+
+Learn more about roles in the [community 
repository](https://github.com/StevenLuMT/pulsar-java-contrib).
diff --git a/build/optaplanner-distribution/src/main/assembly/sources.xml 
b/build/optaplanner-distribution/src/main/assembly/sources.xml
index d1011ce..f22ed5d 100644
--- a/build/optaplanner-distribution/src/main/assembly/sources.xml
+++ b/build/optaplanner-distribution/src/main/assembly/sources.xml
@@ -15,6 +15,17 @@
         <exclude>.gitignore</exclude>
       </excludes>
     </fileSet>
+    <fileSet>
+      <useDefaultExcludes>false</useDefaultExcludes>
+      <directory>../../pulsar-client-contrib</directory>
+      
<outputDirectory>quickstarts/sources/pulsar-client-contrib</outputDirectory>
+      <excludes>
+        <exclude>target/**</exclude>
+        <exclude>build/**</exclude>
+        <exclude>.gradle/**</exclude>
+        <exclude>.gitignore</exclude>
+      </excludes>
+    </fileSet>
     <fileSet>
       <useDefaultExcludes>false</useDefaultExcludes>
       <directory>../../use-cases/school-timetabling</directory>
diff --git a/pom.xml b/pom.xml
index 3f1dfe4..06e7379 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
-
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
https://maven.apache.org/xsd/maven-4.0.0.xsd";>
   <modelVersion>4.0.0</modelVersion>
   <parent>
     <groupId>org.optaplanner</groupId>
@@ -17,6 +16,7 @@
 
   <modules>
     <module>hello-world</module>
+    <module>pulsar-client-contrib</module>
     <module>technology/java-spring-boot</module>
     <module>technology/java-activemq-quarkus</module>
     <module>technology/kotlin-quarkus</module>
diff --git a/pulsar-client-contrib/README.md b/pulsar-client-contrib/README.md
new file mode 100644
index 0000000..b7ed14e
--- /dev/null
+++ b/pulsar-client-contrib/README.md
@@ -0,0 +1,37 @@
+# Apache Pulsar Java Contrib
+
+[![Build](https://github.com/StevenLuMT/pulsar-java-contrib/actions/workflows/build.yml/badge.svg)](https://github.com/StevenLuMT/pulsar-java-contrib/actions/workflows/build.yml)
+
+pulsar-java-contrib is similar to the positioning of 
[opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib):
 
+* One is to prevent the Pulsar main repository from adding too many 
unnecessary functions, which would make Pulsar too bloated, increasing the 
user's usage cost and our maintenance cost.
+* The other is to reduce the user's usage cost by implementing a ready-to-use 
implementation class based on Pulsar's external interface.
+
+these ways achieve these two goals are the plugin library and the yellow 
pages. If you need an easier way to implement some plugin library based on 
Pulsar that cannot be easily satisfied by importing Pulsar directly, then this 
project is hopefully for you.
+
+## Provided Libraries
+
+
+* [Pulsar Client Contrib](./pulsar-client-contrib/README.md)
+
+## Getting Started
+
+```bash
+
+```
+
+## Contributing
+
+pulsar-java-contrib is actively in development.  If you have an idea for a 
similar use case in the metrics, traces, or logging
+domain we would be very interested in supporting it.  Please
+[open an 
issue](https://github.com/StevenLuMT/pulsar-java-contrib/issues/new/choose) to 
share your idea or
+suggestion.  PRs are always welcome and greatly appreciated, but for larger 
functional changes a pre-coding introduction
+can be helpful to ensure this is the correct place and that active or 
conflicting efforts don't exist.
+
+Emeritus maintainers:
+- [Steven Lu](https://github.com/StevenLuMT)
+- [Liangyepian Zhou](https://github.com/liangyepianzhou)
+- [Linlin Duan](https://github.com/AuroraTwinkle)
+- [Fenggan Cai](https://github.com/cai152)
+- [Jia Zhai](https://github.com/jiazhai)
+
+Learn more about roles in the [community 
repository](https://github.com/StevenLuMT/pulsar-java-contrib).
diff --git a/pulsar-client-contrib/pom.xml b/pulsar-client-contrib/pom.xml
new file mode 100644
index 0000000..0374688
--- /dev/null
+++ b/pulsar-client-contrib/pom.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.acme</groupId>
+    <artifactId>pulsar-client-contrib</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <pulsar.version>3.0.5</pulsar.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.pulsar</groupId>
+            <artifactId>pulsar-client-all</artifactId>
+            <version>${pulsar.version}</version>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file
diff --git 
a/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java
 
b/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java
new file mode 100644
index 0000000..8334b9b
--- /dev/null
+++ 
b/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.client.api;
+
+/**
+ * Interface for providing service to execute message listeners.
+ * TODO Duplicate class, to be deleted after merging 
https://github.com/apache/pulsar/pull/22861
+ */
+public interface MessageListenerExecutor {
+
+    /**
+     * select a thread by message to execute the runnable!
+     * <p>
+     * Suggestions:
+     * <p>
+     * 1. The message listener task will be submitted to this executor for 
execution,
+     * so the implementations of this interface should carefully consider 
execution
+     * order if sequential consumption is required.
+     * </p>
+     * <p>
+     * 2. The users should release resources(e.g. threads) of the executor 
after closing
+     * the consumer to avoid leaks.
+     * </p>
+     *
+     * @param message the message
+     * @param runnable the runnable to execute, that is, the message listener 
task
+     */
+    void execute(Message<?> message, Runnable runnable);
+}
diff --git 
a/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/impl/KeySharedMessageListenerExecutor.java
 
b/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/impl/KeySharedMessageListenerExecutor.java
new file mode 100644
index 0000000..8e27bf4
--- /dev/null
+++ 
b/pulsar-client-contrib/src/main/java/org/apache/pulsar/client/api/impl/KeySharedMessageListenerExecutor.java
@@ -0,0 +1,31 @@
+package org.apache.pulsar.client.api.impl;
+
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageListenerExecutor;
+import org.apache.pulsar.client.util.ExecutorProvider;
+
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.ExecutorService;
+
+public class KeySharedMessageListenerExecutor implements 
MessageListenerExecutor {
+    ExecutorProvider executorProvider;
+    public KeySharedMessageListenerExecutor(int numThreads, String 
subscriptionName){
+        this.executorProvider = new ExecutorProvider(numThreads, 
subscriptionName + "listener-executor-");
+    }
+
+    @Override
+    public void execute(Message<?> message, Runnable runnable) {
+        byte[] key = "".getBytes(StandardCharsets.UTF_8);
+        if (message.hasKey()) {
+            key = message.getKeyBytes();
+        } else if (message.hasOrderingKey()) {
+            key = message.getOrderingKey();
+        }
+        // select a thread by message key to execute the runnable!
+        // that say, the message listener task with same order key
+        // will be executed by the same thread
+        ExecutorService executorService = executorProvider.getExecutor(key);
+        // executorService is a SingleThreadExecutor
+        executorService.execute(runnable);
+    }
+}

Reply via email to