remove active mq

This commit is contained in:
Looly 2025-02-17 13:52:51 +08:00
parent 3ad59af2bc
commit 305a9a59b2
9 changed files with 1 additions and 513 deletions

View File

@ -58,7 +58,6 @@
<!-- 消息队列客户端 -->
<kafka.version>3.9.0</kafka.version>
<activemq.version>5.18.6</activemq.version>
<rabbitmq.version>5.24.0</rabbitmq.version>
<rocketmq.version>4.9.8</rocketmq.version>
</properties>
@ -564,12 +563,6 @@
<version>${kafka.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>${activemq.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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;

View File

@ -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