2121import java .util .Optional ;
2222import java .util .concurrent .CountDownLatch ;
2323import java .util .concurrent .Executor ;
24- import java .util .concurrent .ExecutorService ;
25- import java .util .concurrent .Executors ;
26- import java .util .concurrent .ThreadFactory ;
2724import java .util .concurrent .TimeUnit ;
2825import java .util .function .Consumer ;
2926
3532import io .debezium .engine .Header ;
3633import io .debezium .engine .format .SerializationFormat ;
3734
35+ import org .springframework .core .task .SimpleAsyncTaskExecutor ;
36+ import org .springframework .core .task .TaskExecutor ;
3837import org .springframework .integration .debezium .support .DebeziumHeaders ;
3938import org .springframework .integration .debezium .support .DefaultDebeziumHeaderMapper ;
4039import org .springframework .integration .endpoint .MessageProducerSupport ;
4140import org .springframework .lang .Nullable ;
4241import org .springframework .messaging .Message ;
4342import org .springframework .messaging .MessageHeaders ;
4443import org .springframework .messaging .support .HeaderMapper ;
45- import org .springframework .scheduling .concurrent .CustomizableThreadFactory ;
4644import org .springframework .util .Assert ;
4745
4846/**
@@ -60,12 +58,9 @@ public class DebeziumMessageProducer extends MessageProducerSupport {
6058 private DebeziumEngine <ChangeEvent <byte [], byte []>> debeziumEngine ;
6159
6260 /**
63- * Debezium Engine is designed to be submitted to an {@link Executor}
64- * or {@link ExecutorService} for execution by a single thread.
65- * By default, a single-threaded ExecutorService instance is provided configured with a
66- * {@link CustomizableThreadFactory} and a `debezium-` thread prefix.
61+ * Debezium Engine is designed to be submitted to an {@link Executor}.
6762 */
68- private ExecutorService executorService ;
63+ private TaskExecutor taskExecutor ;
6964
7065 private String contentType = "application/json" ;
7166
@@ -75,8 +70,6 @@ public class DebeziumMessageProducer extends MessageProducerSupport {
7570
7671 private boolean enableBatch = false ;
7772
78- private ThreadFactory threadFactory ;
79-
8073 private volatile CountDownLatch lifecycleLatch = new CountDownLatch (0 );
8174
8275 /**
@@ -116,14 +109,12 @@ public void setEnableEmptyPayload(boolean enabled) {
116109 }
117110
118111 /**
119- * Set a {@link ThreadFactory} for the Debezium executor.
120- * Defaults to the {@link CustomizableThreadFactory} with a
121- * {@code debezium:inbound-channel-adapter-thread-} prefix.
122- * @param threadFactory the {@link ThreadFactory} instance to use.
112+ * Set a {@link TaskExecutor} for the Debezium engine task.
113+ * @param taskExecutor the {@link TaskExecutor} to use.
123114 */
124- public void setThreadFactory ( ThreadFactory threadFactory ) {
125- Assert .notNull (threadFactory , "'threadFactory ' must not be null" );
126- this .threadFactory = threadFactory ;
115+ public void setTaskExecutor ( TaskExecutor taskExecutor ) {
116+ Assert .notNull (taskExecutor , "'taskExecutor ' must not be null" );
117+ this .taskExecutor = taskExecutor ;
127118 }
128119
129120 /**
@@ -156,12 +147,10 @@ public String getComponentType() {
156147 protected void onInit () {
157148 super .onInit ();
158149
159- if (this .threadFactory == null ) {
160- this .threadFactory = new CustomizableThreadFactory (getComponentName () + "-thread-" );
150+ if (this .taskExecutor == null ) {
151+ this .taskExecutor = new SimpleAsyncTaskExecutor (getComponentName () + "-thread-" );
161152 }
162153
163- this .executorService = Executors .newSingleThreadExecutor (this .threadFactory );
164-
165154 if (!this .enableBatch ) {
166155 this .debeziumEngineBuilder .notifying (new StreamChangeEventConsumer <>());
167156 }
@@ -178,7 +167,7 @@ protected void doStart() {
178167 return ;
179168 }
180169 this .lifecycleLatch = new CountDownLatch (1 );
181- this .executorService .execute (() -> {
170+ this .taskExecutor .execute (() -> {
182171 try {
183172 // Runs the debezium connector and deliver database changes to the registered consumer. This method
184173 // blocks until the connector is stopped.
@@ -213,19 +202,6 @@ protected void doStop() {
213202 }
214203 }
215204
216- @ Override
217- public void destroy () {
218- super .destroy ();
219-
220- this .executorService .shutdown ();
221- try {
222- this .executorService .awaitTermination (5 , TimeUnit .SECONDS );
223- }
224- catch (InterruptedException e ) {
225- throw new IllegalStateException ("Debezium failed to close!" , e );
226- }
227- }
228-
229205 @ Nullable
230206 private <T > Message <?> toMessage (ChangeEvent <T , T > changeEvent ) {
231207 Object key = changeEvent .key ();
0 commit comments