我正在创建一个简单的 Thorntail 服务,它将向远程 ActiveMQ 队列写入一条文本消息,并让 MDB 使用该消息。为了对此进行测试,我在本地 Docker 容器中运行了 ActiveMQ。我的 docker-compose.yml
文件的相关部分如下所示:
activemq:
image: webcenter/activemq
ports:
- 1883:1883
- 5672:5672
- 8161:8161
- 61613:61613
- 61614:61614
- 61616:61616
environment:
- ACTIVEMQ_CONFIG_NAME=holocron-mq
- ACTIVEMQ_CONFIG_DEFAULTACCOUNT=false
- ACTIVEMQ_ADMIN_LOGIN=mqadmin
- ACTIVEMQ_ADMIN_PASSWORD=password
- ACTIVEMQ_CONFIG_QUEUES_queue1=myqueue1
- ACTIVEMQ_CONFIG_SCHEDULERENABLED=true
- ACTIVEMQ_USERS_edgeproducer=password
- ACTIVEMQ_USERS_edgeconsumer=password
我的 Thorntail project-defaults.yml
文件已配置为使用此配置连接到此“远程”服务器:
swarm:
network:
socket-binding-groups:
standard-sockets:
outbound-socket-bindings:
remote-activemq-socket-binding:
remote-host: 127.0.0.1
remote-port: 61616
messaging-activemq:
servers:
default:
remote-connectors:
remote-activemq-connector:
socket-binding: remote-activemq-socket-binding
pooled-connection-factories:
remote-connection-factory:
user: edgeproducer
password: password
connectors:
- remote-activemq-connector
entries:
- 'java:/jms/remote-mq'
- 'java:/DefaultJMSConnectionFactory'
jms-queues:
session-tracking-queue:
entries:
entry: 'java:/jms/queue/testQueue'
我的 JAX-RS 服务具有以下 2 个 JMS 属性(最终)允许我写入队列:
@Inject
@JMSConnectionFactory("java:/jms/remote-mq")
private JMSContext jmsContext = null;
@Resource(mappedName = "java:/jms/queue/testQueue")
private Queue processingQueue = null;
最后,我的 MDB 具有以下注释以允许它从队列中读取:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/testQueue"),
@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "10") })
@ResourceAdapter("remote-connection-factory")
但是,当我启动 Thorntail uberjar 时,出现以下错误:
AMQ214031: Failed to decode buffer, disconnect immediately.: java.lang.IllegalStateException: java.lang.IllegalArgumentException: AMQ119032: Invalid type: 1
AMQ212037: Connection failure has been detected: java.lang.IllegalArgumentException: AMQ119032: Invalid type: 1 [code=GENERIC_EXCEPTION]
我不确定我的配置中到底遗漏了什么导致了这个问题。任何人都可以阐明我做错了什么吗?
最佳答案
您正在尝试将 ActiveMQ Artemis“核心”JMS 客户端(即 Thorntail 中的默认 JMS 客户端实现)与 ActiveMQ 5.x 代理一起使用。 ActiveMQ Artemis 是下一代 ActiveMQ 消息代理,Artemis 核心 JMS 客户端无法与 5.x 代理通信。我建议您在 Docker 容器中使用 ActiveMQ Artemis。它向后兼容 5.x 代理支持的 OpenWire JMS 客户端实现,它还支持所有其他协议(protocol)(例如 AMQP、STOMP、MQTT)。
关于java - Thorntail JMS 到远程 ActiveMQ 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174631/