如何使用Payara(Micro)设置ActiveMQ Artemis

问题描述 投票:1回答:1

我想创建一个设置来评估JMS的消息传递。目标环境是正常的Payara,但设置简单,我想使用Payara Micro(捆绑罐)进行测试。这样,我想创建一个可以轻松移植的设置。使用JNDI查找,这方面的代码应该没有问题。另外,编码部分并不难。我想用此设置进行测试的事情:-消费者使用消息驱动的bean-制作人-访问管理队列(我想测试如何启用蓝色/绿色部署)

使用经典ActiveMQ的rar,事情比较容易。我设置了一个post-boot-commands.txt来部署和配置具有以下内容的资源适配器:


create-resource-adapter-config  --property ServerUrl='tcp://localhost:61616':UserName='admin':Password='admin' activemq-rar-5.15.11

create-connector-connection-pool  --raname activemq-rar-5.15.11 --connectiondefinition javax.jms.ConnectionFactory --ping true --isconnectvalidatereq true jms/myConnectionPool

create-connector-resource --poolname jms/myConnectionPool jms/myConnectionFactory

create-admin-object --raname activemq-rar-5.15.11 --restype javax.jms.Queue --property PhysicalName=Q1 jms/myQueue

这使Payara Micro在部署我的应用程序war-file之前部署并配置rar。然后可以使用以下配置编写消息驱动的Bean:

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "Q1"),
        @ActivationConfigProperty(propertyName = "resourceAdapter", propertyValue = "activemq-rar-5.15.11"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyMDB implements MessageListener {
   ...
}

由于制作人很容易,所以我在这里跳过这一部分。在我开始处理管理队列之前,一切工作都很好。在代理附带的管理示例(使用一些不赞成使用的代码:())之后,我遇到了冲突,因为该解决方案使用了来自artemis客户端的代码,然后与经典ActiveMQ rar中的ConnectionFactory类冲突。我尝试将经典的ActiveMQs rar与ActiveMQ Artemis一起使用,我尝试切换到artemis rar。不幸的是,找到有关如何使用Payara配置资源适配器的信息,这真是天壤之别。

通过查看类ActiveMQResourceAdapter的源,我得出了以下配置:

deploy --type rar /home/tools/artemis-rar-2.11.0.rar

create-resource-adapter-config  --property connectionParameters='host=localhost;port=61616':JndiParams='java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory;connectionFactory.ConnectionFactory=tcp://localhost:61616;queue.jms/myQueue=Q1':useJndi='true':entries='ConnectionFactory':userName='admin':password='admin' artemis-rar-2.11.0

create-connector-connection-pool --raname artemis-rar-2.11.0 --connectiondefinition javax.jms.ConnectionFactory --ping true --isconnectvalidatereq true jms/ConnectionFactoryPool

create-connector-resource --poolname jms/myConnectionPool jms/myConnectionFactory

create-admin-object --raname artemis-rar-2.11.0 --restype javax.jms.Queue --property PhysicalName=Q1 jms/myQueue

JNDI属性是一种尝试从示例模仿jndi.properties内容的尝试。好的部分是,在启动时Payara Micro上说:

[2020-03-26T20:51:58.812 + 0100] [] [INFO] [] [org.apache.activemq.artemis.ra] [tid:_ThreadID = 48 _ThreadName = pool-18-thread-1] [ timeMillis:1585252318812] [levelValue:800] AMQ151007:资源适配器已启动

坏消息是它接着继续:

[[2020-03-26T20:51:58.843 + 0100] [] [WARNUNG] [] [fish.payara.boot.runtime.BootCommand] [tid:_ThreadID = 1 _ThreadName = main] [timeMillis:1585252318843] [levelValue :900]引导命令create-connector-connection-pool失败PlainTextActionReporterFAILURE无效的连接定义。找不到具有连接定义javax.jms.ConnectionFactory的连接器模块。

和:

[2020-03-26T20:51:58.850 + 0100] [] [WARNUNG] [] [fish.payara.boot.runtime.BootCommand] [tid:_ThreadID = 1 _ThreadName = main] [timeMillis:1585252318850] [levelValue :900]在连接器连接池列表中找不到启动命令create-connector-resource失败的PlainTextActionReporterFAILUREAttribute值(池名称= jms / myConnectionPool)。

和:

[[2020-03-26T20:51:58.856 + 0100] [] [WARNUNG] [] [fish.payara.boot.runtime.BootCommand] [tid:_ThreadID = 1 _ThreadName = main] [timeMillis:1585252318856] [levelValue :900]引导命令创建管理对象失败PlainTextActionReporterFAILUREResource适配器artemis-rar-2.11.0不包含管理对象的任何资源类型。请指定另一个res-adapter。

因此,它无法注册连接工厂和队列。结果,该应用程序稍后在查找资源时会引发异常。

我必须承认,我对JMS和资源适配器/ JCA没有经验。我已经为此花了几天的时间,实在令人沮丧。因此,欢迎您提供任何帮助。

payara payara-micro
1个回答
0
投票

现在回答我自己的问题。感觉花了我很长时间才弄清楚,但是我终于使它起作用了。因此,使用asadmin的正确配置如下:

deploy --type rar /home/tools/artemis-rar-2.11.0.rar

create-resource-adapter-config  --property ConnectorClassName='org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory':ConnectionParameters='host=localhost;port=61616':UserName='admin':Password='admin' artemis-rar-2.11.0

create-connector-connection-pool --raname artemis-rar-2.11.0 --connectiondefinition org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactory --ping true jms/ConnectionFactoryPool

create-connector-resource --poolname jms/ConnectionFactoryPool jms/myConnectionFactory

如您所见,没有管理对象的配置。原因是artemis rar似乎没有提供任何管理对象。这样,您无法通过jndi查找目的地(队列和主题),但是需要使用目的地物理名称通过JMS会话创建目的地。现在,MDB的配置:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "Q1"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "resourceAdapter", propertyValue = "artemis-rar-2.11.0")
})
public class MyMDB implements MessageListener {
    ...
}

不过,有一个问题:您无法访问管理队列来控制代理。尽管您可以创建会话和目标,但是消息必须属于特定类别。但是,已配置的连接工厂不会返回必需的类,从而导致运行时异常。因此,需要搜索其他方法来访问管理部分。

说了这么多,我想与一些建设性的评论家分享有关Artemis开发人员偶然发现的情况。尽管该文档解释说对于Java EE用户来说,存在用于artemis的JCA体系结构,但没有地方解释如何设置/配置它。甚至在maven上也没有指向rar文件的链接(该文件具有奇怪的goup-id btw)。当然,Artemis附带了很多示例,但是从我看到的内容中,没有一个显示如何设置rar的示例。相反,它们是使用client-jar设置的,但是我怀疑这种方法是否适用于MDB。首先是rar-example,它显示了配置属性,但没有显示它们的值(至少,不是ConnectorClassName属性的)。然后,只能查看github上的源代码,并尝试转换其他用户用于其他应用程序服务器的配置。让我知道我的方法是否有问题,但是使用经典的ActiveMQ设置起来要简单得多。

© www.soinside.com 2019 - 2024. All rights reserved.