From 305a9a59b2d95c929004ad455c472295278ea729 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 17 Feb 2025 13:52:51 +0800 Subject: [PATCH] remove active mq --- hutool-extra/pom.xml | 7 - .../mq/engine/activemq/ActiveMQEngine.java | 81 ------------ .../mq/engine/activemq/package-info.java | 22 ---- .../extra/mq/engine/jms/DestinationType.java | 34 ----- .../hutool/extra/mq/engine/jms/JMSEngine.java | 105 --------------- .../extra/mq/engine/jms/JMSProducer.java | 123 ------------------ .../extra/mq/engine/jms/JSMConsumer.java | 118 ----------------- .../extra/mq/engine/jms/package-info.java | 22 ---- ...rg.dromara.hutool.extra.mq.engine.MQEngine | 2 +- 9 files changed, 1 insertion(+), 513 deletions(-) delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/ActiveMQEngine.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/package-info.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/DestinationType.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSEngine.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSProducer.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JSMConsumer.java delete mode 100644 hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/package-info.java diff --git a/hutool-extra/pom.xml b/hutool-extra/pom.xml index 68f776f31..609527278 100755 --- a/hutool-extra/pom.xml +++ b/hutool-extra/pom.xml @@ -58,7 +58,6 @@ 3.9.0 - 5.18.6 5.24.0 4.9.8 @@ -564,12 +563,6 @@ ${kafka.version} provided - - org.apache.activemq - activemq-client - ${activemq.version} - provided - com.rabbitmq amqp-client diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/ActiveMQEngine.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/ActiveMQEngine.java deleted file mode 100644 index 15b0d8dd6..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/ActiveMQEngine.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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.dromara.hutool.extra.mq.engine.activemq; - -import jakarta.jms.Connection; -import jakarta.jms.ConnectionFactory; -import org.apache.activemq.ActiveMQConnectionFactory; -import org.dromara.hutool.core.lang.Assert; -import org.dromara.hutool.extra.mq.MQConfig; -import org.dromara.hutool.extra.mq.engine.jms.JMSEngine; - -/** - * ActiveMQ引擎 - * - * @author Looly - * @since 6.0.0 - */ -public class ActiveMQEngine extends JMSEngine { - - /** - * 默认构造 - */ - public ActiveMQEngine() { - super((Connection) null); - // SPI方式加载时检查库是否引入 - Assert.notNull(org.apache.activemq.ActiveMQConnectionFactory.class); - } - - /** - * 构造 - * - * @param config 配置 - */ - public ActiveMQEngine(final MQConfig config) { - super(createFactory(config)); - } - - /** - * 构造 - * - * @param factory {@link ConnectionFactory} - */ - public ActiveMQEngine(final ActiveMQConnectionFactory factory) { - super(factory); - } - - @Override - public ActiveMQEngine init(final MQConfig config) { - super.init(createFactory(config)); - return this; - } - - /** - * 创建{@link ActiveMQConnectionFactory} - * - * @param config 配置 - * @return {@link ActiveMQConnectionFactory} - */ - private static ActiveMQConnectionFactory createFactory(final MQConfig config) { - final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); - factory.setBrokerURL(config.getBrokerUrl()); - - // TODO 配置其他参数 - - return factory; - } -} diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/package-info.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/package-info.java deleted file mode 100644 index 311af9dbf..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/activemq/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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. - */ - -/** - * ActiveMQ消息队列引擎实现 - * - * @author Looly - */ -package org.dromara.hutool.extra.mq.engine.activemq; diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/DestinationType.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/DestinationType.java deleted file mode 100644 index 6849f1bd1..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/DestinationType.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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.dromara.hutool.extra.mq.engine.jms; - -/** - * 目标类型 - * - * @author Looly - */ -public enum DestinationType { - /** - * 主题 - */ - TOPIC, - - /** - * 队列 - */ - QUEUE; -} diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSEngine.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSEngine.java deleted file mode 100644 index bab9e98a9..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSEngine.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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.dromara.hutool.extra.mq.engine.jms; - -import jakarta.jms.Connection; -import jakarta.jms.ConnectionFactory; -import jakarta.jms.JMSException; -import jakarta.jms.Session; -import org.dromara.hutool.core.io.IoUtil; -import org.dromara.hutool.extra.mq.Consumer; -import org.dromara.hutool.extra.mq.MQConfig; -import org.dromara.hutool.extra.mq.MQException; -import org.dromara.hutool.extra.mq.Producer; -import org.dromara.hutool.extra.mq.engine.MQEngine; - -import java.io.Closeable; -import java.io.IOException; - -/** - * ActiveMQ引擎 - * - * @author Looly - * @since 6.0.0 - */ -public class JMSEngine implements MQEngine, Closeable { - - private Connection connection; - - /** - * 构造 - * - * @param connection {@link Connection} - */ - public JMSEngine(final Connection connection) { - this.connection = connection; - } - - /** - * 构造 - * - * @param factory {@link ConnectionFactory} - */ - @SuppressWarnings("resource") - public JMSEngine(final ConnectionFactory factory) { - init(factory); - } - - @Override - public JMSEngine init(final MQConfig config) { - throw new MQException("Unsupported JMSEngine create by MQConfig!"); - } - - /** - * 初始化 - * - * @param factory {@link ConnectionFactory} - * @return this - */ - public JMSEngine init(final ConnectionFactory factory){ - try { - this.connection = factory.createConnection(); - this.connection.start(); - } catch (final JMSException e) { - throw new MQException(e); - } - return this; - } - - @Override - public Producer getProducer() { - return new JMSProducer(createSession()); - } - - @Override - public Consumer getConsumer() { - return new JSMConsumer(createSession()); - } - - private Session createSession() { - try { - return this.connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } catch (final JMSException e) { - throw new MQException(e); - } - } - - @Override - public void close() throws IOException { - IoUtil.closeQuietly(this.connection); - } -} diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSProducer.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSProducer.java deleted file mode 100644 index 17a28e0fa..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JMSProducer.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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.dromara.hutool.extra.mq.engine.jms; - -import jakarta.jms.*; -import org.dromara.hutool.core.io.IoUtil; -import org.dromara.hutool.extra.mq.MQException; -import org.dromara.hutool.extra.mq.Message; -import org.dromara.hutool.extra.mq.Producer; - -import java.io.IOException; - -/** - * ActiveMQ消息生产者 - * - * @author Looly - * @since 6.0.0 - */ -public class JMSProducer implements Producer { - - private final Session session; - private MessageProducer producer; - - /** - * 构造 - * - * @param session Session - */ - public JMSProducer(final Session session) { - this.session = session; - } - - /** - * 设置主题 - * - * @param topic 主题 - * @return this - */ - public JMSProducer setTopic(final String topic) { - final Destination destination = createDestination(topic, DestinationType.TOPIC); - this.producer = createProducer(destination); - return this; - } - - /** - * 设置队列 - * - * @param queue 队列 - * @return this - */ - public JMSProducer setQueue(final String queue) { - final Destination destination = createDestination(queue, DestinationType.QUEUE); - this.producer = createProducer(destination); - return this; - } - - @Override - public void send(final Message message) { - try { - final BytesMessage bytesMessage = session.createBytesMessage(); - bytesMessage.writeBytes(message.content()); - this.producer.send(bytesMessage); - } catch (final JMSException e) { - throw new MQException(e); - } - } - - @Override - public void close() throws IOException { - IoUtil.closeQuietly(this.producer); - IoUtil.closeQuietly(this.session); - } - - /** - * 创建消息生产者 - * - * @param destination 目的地 - * @return this - */ - private MessageProducer createProducer(final Destination destination) { - try { - return session.createProducer(destination); - } catch (final JMSException e) { - throw new MQException(e); - } - } - - /** - * 创建消息目的地 - * - * @param name 消息目的地名称 - * @param type 消息目的地类型 - * @return this - */ - private Destination createDestination(final String name, final DestinationType type) { - try { - switch (type){ - case QUEUE: - return session.createQueue(name); - case TOPIC: - return session.createTopic(name); - default: - throw new MQException("Unknown destination type: " + type); - } - } catch (final JMSException e) { - throw new MQException(e); - } - } -} diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JSMConsumer.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JSMConsumer.java deleted file mode 100644 index 8399eaa79..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/JSMConsumer.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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.dromara.hutool.extra.mq.engine.jms; - -import jakarta.jms.*; -import org.dromara.hutool.core.io.IoUtil; -import org.dromara.hutool.extra.mq.Consumer; -import org.dromara.hutool.extra.mq.MQException; -import org.dromara.hutool.extra.mq.MessageHandler; - -import java.io.IOException; - -/** - * ActiveMQ消息消费者 - * - * @author Looly - * @since 6.0.0 - */ -public class JSMConsumer implements Consumer { - - private final Session session; - private MessageConsumer consumer; - - /** - * 构造 - * - * @param session Session - */ - public JSMConsumer(final Session session) { - this.session = session; - } - - /** - * 设置主题 - * - * @param topic 主题 - * @return this - */ - public JSMConsumer setTopic(final String topic) { - try { - this.consumer = this.session.createConsumer(this.session.createTopic(topic)); - } catch (final JMSException e) { - throw new MQException(e); - } - return this; - } - - @Override - public void subscribe(final MessageHandler messageHandler) { - final Message message; - try{ - message = consumer.receive(3000); - } catch (final JMSException e){ - throw new MQException(e); - } - - messageHandler.handle(new JMSMessage(message)); - } - - @Override - public void listen(final MessageHandler messageHandler) { - try { - consumer.setMessageListener(message -> messageHandler.handle(new JMSMessage(message))); - } catch (final JMSException e) { - throw new MQException(e); - } - } - - @Override - public void close() throws IOException { - IoUtil.closeQuietly(this.consumer); - IoUtil.closeQuietly(this.session); - } - - /** - * JMS消息包装 - */ - private static class JMSMessage implements org.dromara.hutool.extra.mq.Message{ - - private final Message message; - - private JMSMessage(final Message message) { - this.message = message; - } - - @Override - public String topic() { - try { - return message.getJMSDestination().toString(); - } catch (final JMSException e) { - throw new MQException(e); - } - } - - @Override - public byte[] content() { - try { - return message.getBody(byte[].class); - } catch (final JMSException e) { - throw new MQException(e); - } - } - } -} diff --git a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/package-info.java b/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/package-info.java deleted file mode 100644 index 486191811..000000000 --- a/hutool-extra/src/main/java/org/dromara/hutool/extra/mq/engine/jms/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2025 Hutool Team and hutool.cn - * - * Licensed 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. - */ - -/** - * JMS(Java Message Service)消息队列引擎实现 - * - * @author Looly - */ -package org.dromara.hutool.extra.mq.engine.jms; diff --git a/hutool-extra/src/main/resources/META-INF/services/org.dromara.hutool.extra.mq.engine.MQEngine b/hutool-extra/src/main/resources/META-INF/services/org.dromara.hutool.extra.mq.engine.MQEngine index 5c5691444..8c3533b3e 100644 --- a/hutool-extra/src/main/resources/META-INF/services/org.dromara.hutool.extra.mq.engine.MQEngine +++ b/hutool-extra/src/main/resources/META-INF/services/org.dromara.hutool.extra.mq.engine.MQEngine @@ -16,4 +16,4 @@ org.dromara.hutool.extra.mq.engine.kafka.KafkaEngine org.dromara.hutool.extra.mq.engine.rabbitmq.RabbitMQEngine -org.dromara.hutool.extra.mq.engine.activemq.ActiveMQEngine +org.dromara.hutool.extra.mq.engine.activemq.ActiveMQ5Engine